# Split and Split Again

**URL:** https://discourse.nodered.org/t/split-and-split-again/34215
**Category:** General
**Created:** [14 October 2020 04:05 UTC](https://discourse.nodered.org/t/split-and-split-again/34215 "2020-10-14T04:05:07Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![radiosavage](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/radiosavage/32/37684_2.png) [@radiosavage](https://discourse.nodered.org/u/radiosavage)
#### Post date: [14 October 2020 04:05 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/1 "2020-10-14T04:05:07Z")

</div>

I am new to Node-Red so I hope that I can explain this in a way that makes sense. I am getting data from a program called Pira CZ that triggers when silence is on our station. It uses HTTP Get to input into Node Red and this is what it picks up.

{"0":"STATION:KXKX,STATUS:SILENT,DATE:2020-10-13,TIME:17-58-08"}

I can change the format if it makes sense. I then need to run it through a function node so that I can split it.

STATION:KDDB,STATUS:SILENT,DATE:2020-10-13,TIME:18-00-13

I then split it at the commas to give me four separate values:

STATION:KDDB  
STATUS:SILENT  
DATE:2020-10-13  
TIME:18-01-53

Now, I want to Split these so that the left is the key and the right is the value. I feel like this could be all done in the function node but I lack that level of programming. I am still learning and no better way then to figure out what hasn't worked but I am stumped at this point. I want to be able to log this information as well as send to the UI. There is also a message that will tell us when the station is back to normal as well.  
Aloha!

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [14 October 2020 06:18 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/2 "2020-10-14T06:18:19Z")

</div>

If you select return a json object in the http request, you will get key value pairs in a javasript object. no need for all the spliting

Change your return to  
`{"0":{"STATION":"KXKX","STATUS":"SILENT","DATE":"2020-10-13","TIME":"17-58-08"}]`

or  
`[{"STATION":"KXKX","STATUS":"SILENT","DATE":"2020-10-13","TIME":"17-58-08"}]`

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [14 October 2020 06:18 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/3 "2020-10-14T06:18:40Z")

</div>

> [@radiosavage](#):
>
> I can change the format if it makes sense.

If you can change the format, why don't you put each value in their own property?

---

<div class="post-metadata">

### Author: ![radiosavage](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/radiosavage/32/37684_2.png) [@radiosavage](https://discourse.nodered.org/u/radiosavage)
#### Post date: [14 October 2020 19:53 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/4 "2020-10-14T19:53:00Z")

</div>

I meant that I can send a single line formatted in different ways. I guess what I said is misleading or I am missing the approach you are suggesting?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [14 October 2020 19:58 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/5 "2020-10-14T19:58:10Z")

</div>

> [@radiosavage](#):
>
> I meant that I can send a single line formatted in different ways

JSON is a string. format the data as JSON then its a simple case of turning it into a JS object & accessing values like...

```auto
data.station
data.status
data.date
//etc

```

Question - do you generate this `{"0":"STATION:KXKX,STATUS:SILENT,DATE:2020-10-13,TIME:17-58-08"}` or do you only generate `STATION:KXKX,STATUS:SILENT,DATE:2020-10-13,TIME:17-58-08` ?

---

<div class="post-metadata">

### Author: ![radiosavage](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/radiosavage/32/37684_2.png) [@radiosavage](https://discourse.nodered.org/u/radiosavage)
#### Post date: [14 October 2020 20:09 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/6 "2020-10-14T20:09:18Z")

</div>

> [@Steve-Mcl](#):
>
> `{"0":"STATION:KXKX,STATUS:SILENT,DATE:2020-10-13,TIME:17-58-08"}`

I am producing the first one. I get what you are saying and apologize for my lack of knowledge on JSON. Still learning all this. Appreciate the patience.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [14 October 2020 20:11 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/7 "2020-10-14T20:11:51Z")

</div>

Can you format it like this then?  
`{"STATION":"KXKX","STATUS":"SILENT","DATE":"2020-10-13","TIME":"17-58-08"}`

---

<div class="post-metadata">

### Author: ![radiosavage](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/radiosavage/32/37684_2.png) [@radiosavage](https://discourse.nodered.org/u/radiosavage)
#### Post date: [14 October 2020 20:15 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/8 "2020-10-14T20:15:09Z")

</div>

I sure can. I was about to reply to your earlier message. I am doing it know. I take it at that point I insert into the JSON node and convert?

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [14 October 2020 20:16 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/9 "2020-10-14T20:16:33Z")

</div>

if you want to or you can set the http request to return a json object, it will then decode your json string into a javascript object.

---

<div class="post-metadata">

### Author: ![radiosavage](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/radiosavage/32/37684_2.png) [@radiosavage](https://discourse.nodered.org/u/radiosavage)
#### Post date: [14 October 2020 20:55 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/10 "2020-10-14T20:55:29Z")

</div>

> [@E1cid](#):
>
> Can you format it like this then?  
> `{"STATION":"KXKX","STATUS":"SILENT","DATE":"2020-10-13","TIME":"17-58-08"}`

I have and this is what I see on the other side of the HTTP GET Node in the DEBUG.

{"{"STATION":"KDDB","STATUS":"SILENT","DATE":"2020-10-14","TIME":"10-52-00"}":""}

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [14 October 2020 20:58 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/11 "2020-10-14T20:58:45Z")

</div>

you need to remove the {" from beginning and ":""} from end.

Or if not possible  
try  
`{"0":{"STATION":"KXKX","STATUS":"SILENT","DATE":"2020-10-13","TIME":"17-58-08"}}`

Or show us a screeshot of how you are editing this string.

---

<div class="post-metadata">

### Author: ![radiosavage](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/radiosavage/32/37684_2.png) [@radiosavage](https://discourse.nodered.org/u/radiosavage)
#### Post date: [15 October 2020 00:32 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/12 "2020-10-15T00:32:30Z")

</div>

OK. I have learned a little more on how this program is adding the {" and the ":""}. It seems I can stop this by adding this in front 0= So the line looks like this in the program at this point:

 ![Screen Shot 2020-10-14 at 2.31.43 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/284bd03f1a239c88c7514aec2715a691c3e3889c.png)

This is the output now in the debug window:  
{"STATION":"KDDB","STATUS":"SILENT","DATE":"2020-10-14","TIME":"14-18-23"}

I feel like I am getting a little closer.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [15 October 2020 06:55 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/13 "2020-10-15T06:55:31Z")

</div>

OK that looks correct, now in the http request node change return a UTF-8 string to parse json object.

Also a screen shot of the debug msg expanded.

---

<div class="post-metadata">

### Author: ![radiosavage](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/radiosavage/32/37684_2.png) [@radiosavage](https://discourse.nodered.org/u/radiosavage)
#### Post date: [17 October 2020 22:24 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/14 "2020-10-17T22:24:06Z")

</div>

Thanks. I had to step away for some other work.

Here is the screenshot:  
 ![Screen Shot 2020-10-17 at 12.21.18 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3f187c8987e6b4e9f12b26bfdfdc118d3387a025.png)

I am actually using the HTTP IN node since the program sends an HTTP Get. I know that if I use the JSON expression it allows me to parse the data. I think I have just run into a limitation on what the software can send in the GET request.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [17 October 2020 23:01 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/15 "2020-10-17T23:01:12Z")

</div>

Ok we can work with it that way  
Try this to convert to object and remove the object [0]

```auto
[{"id":"70884b11.0d3814","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload[0]","v":"{\"STATION\":\"KXKX\",\"STATUS\":\"SILENT\",\"DATE\":\"2020-10-13\",\"TIME\":\"17-58-08\"}","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":70,"y":960,"wires":[["70d0c20b.aaab9c"]]},{"id":"70d0c20b.aaab9c","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":960,"wires":[["4d272653.0588f8"]]},{"id":"4d272653.0588f8","type":"json","z":"8d22ae29.7df6d","name":"","property":"payload","action":"obj","pretty":false,"x":450,"y":960,"wires":[["2f916e88.bb5672"]]},{"id":"2f916e88.bb5672","type":"debug","z":"8d22ae29.7df6d","name":"success","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":960,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [17 October 2020 23:29 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/16 "2020-10-17T23:29:00Z")

</div>

I was thinking what happens if you structure your Pira CZ call like this

```auto
STATION=KXKX&STATUS=SILENT&DATE=%date&TIME=%time

```

---

<div class="post-metadata">

### Author: ![radiosavage](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/radiosavage/32/37684_2.png) [@radiosavage](https://discourse.nodered.org/u/radiosavage)
#### Post date: [17 October 2020 23:51 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/17 "2020-10-17T23:51:42Z")

</div>

> [@E1cid](#):
>
> ```auto
> STATION=KXKX&STATUS=SILENT&DATE=%date&TIME=%time
> 
> ```

So Simple and so right. This did the trick. It formatted perfectly.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [18 October 2020 06:33 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/18 "2020-10-18T06:33:18Z")

</div>

Yeah should have spotted it earlier. It was when you said that the software was making a get request, a idea popped in to my head.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [1 November 2020 06:33 UTC](https://discourse.nodered.org/t/split-and-split-again/34215/19 "2020-11-01T06:33:22Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
