# Parsing ASCII Text - Resolved

**URL:** <https://discourse.nodered.org/t/parsing-ascii-text-resolved/20703>\
**Category:** General\
**Created:** [21 January 2020 22:51 UTC](https://discourse.nodered.org/t/parsing-ascii-text-resolved/20703 "2020-01-21T22:51:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![n61ab](https://avatars.discourse-cdn.com/v4/letter/n/cc9497/32.png) [@n61ab](https://discourse.nodered.org/u/n61ab)\
**Post date:** [21 January 2020 22:51 UTC](https://discourse.nodered.org/t/parsing-ascii-text-resolved/20703/1 "2020-01-21T22:51:09Z")

</div>

I am receiving data formated as ASCII text as follows:

65,90,58,49,50,57,46,57,13 ; which means AZ:129.9

Using the Node-Red "text" ui node, it converts the message code to decimal as shown above. Good.

I want to use the same data to input into a ui gauge, so I need to strip away the "AZ:" portion of the message.

I am a novice Node-Red user.

What are the ways parsing can be done?

Alan

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [21 January 2020 23:59 UTC](https://discourse.nodered.org/t/parsing-ascii-text-resolved/20703/2 "2020-01-21T23:59:55Z")

</div>

Can you pass a message containing that data to a debug node and then share a screenshot of the message? That will help us determine exactly what you've got and from that, how best to convert it to a proper JavaScript string you can start extracting bits from.

---

<div class="post-metadata">

**Author:** ![n61ab](https://avatars.discourse-cdn.com/v4/letter/n/cc9497/32.png) [@n61ab](https://discourse.nodered.org/u/n61ab)\
**Post date:** [22 January 2020 01:26 UTC](https://discourse.nodered.org/t/parsing-ascii-text-resolved/20703/3 "2020-01-22T01:26:28Z")

</div>

Thanks, Nick.

Here is the screenshot. I expanded two of the messages so you can see how Node-Red is handling the object.

Alan

Alan

 ![Data](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/43cd8ef0175a6296df412b3d408dd939853ce9d6.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 January 2020 08:46 UTC](https://discourse.nodered.org/t/parsing-ascii-text-resolved/20703/4 "2020-01-22T08:46:17Z")

</div>

Try in a Function node

```auto
msg.payload = msg.payload.toString()
return msg

```

and feed that into a debug node and check it gives you "AZ:129.9". If so then feed that into JSON node which should convert it from a JSON string to a javascript object. Again check in a debug node that you get `{AZ: 129.9}`. If so then you can reference the value as `msg.payload.AZ` in the gauge node.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [22 January 2020 09:42 UTC](https://discourse.nodered.org/t/parsing-ascii-text-resolved/20703/5 "2020-01-22T09:42:32Z")

</div>

> [@Colin](#):
>
> check it gives you "AZ:129.9". If so then feed that into JSON node which should convert it from a JSON string to a javascript object.

No it won't - `AZ:129/9` is not valid JSON.

@n61ab once you have the String, you can use the various JavaScript String functions to split it up as you require - [String - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 January 2020 10:23 UTC](https://discourse.nodered.org/t/parsing-ascii-text-resolved/20703/6 "2020-01-22T10:23:16Z")

</div>

I was confused there by the fact that you have 129/9 instead of 129.9, but I see what you mean. The string needs to be surrounded by { } to be JSON.

@n61ab use this in the function node instead, to make it valid JSON

```auto
msg.payload = "{" + msg.payload.toString() + "}"
return msg

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [22 January 2020 11:04 UTC](https://discourse.nodered.org/t/parsing-ascii-text-resolved/20703/7 "2020-01-22T11:04:54Z")

</div>

@Colin that still isn't valid JSON - the `AZ` would need to be in quotes - `"AZ"`. Forcing it into a JSON format isn't worth the effort.

@n61ab the screenshot you've shared shows that `msg.payloads` is a `Buffer` type. That is why the `toString()` function Colin suggests works.

Here's a quick function that will do the string conversion and then split out the number:

```auto
// Convert Buffer to String:
var data = msg.payload.toString()
// Split it using the `:` character
var parts = data.split(":");

// parts is now a two-element array, containing "AZ" and "129.9"
// use the second element:
msg.payload = parts[1];

return msg

```

---

<div class="post-metadata">

**Author:** ![n61ab](https://avatars.discourse-cdn.com/v4/letter/n/cc9497/32.png) [@n61ab](https://discourse.nodered.org/u/n61ab)\
**Post date:** [22 January 2020 11:05 UTC](https://discourse.nodered.org/t/parsing-ascii-text-resolved/20703/8 "2020-01-22T11:05:34Z")

</div>

Colin and knolleary

Thanks for your help. I will give this a try this afternoon and let you know how I do.

Alan

---

<div class="post-metadata">

**Author:** ![n61ab](https://avatars.discourse-cdn.com/v4/letter/n/cc9497/32.png) [@n61ab](https://discourse.nodered.org/u/n61ab)\
**Post date:** [22 January 2020 11:18 UTC](https://discourse.nodered.org/t/parsing-ascii-text-resolved/20703/9 "2020-01-22T11:18:11Z")

</div>

knolleary

I could not wait! Your function works great! How can I say thank-you enough?

Alan

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 January 2020 11:35 UTC](https://discourse.nodered.org/t/parsing-ascii-text-resolved/20703/10 "2020-01-22T11:35:58Z")

</div>

> [@knolleary](#):
>
> that still isn't valid JSON

Doh, I must remember to engage brain before typing.
