# Parse a random json

**URL:** <https://discourse.nodered.org/t/parse-a-random-json/43085>\
**Category:** General\
**Created:** [23 March 2021 12:56 UTC](https://discourse.nodered.org/t/parse-a-random-json/43085 "2021-03-23T12:56:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Napster](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@Napster](https://discourse.nodered.org/u/Napster)\
**Post date:** [23 March 2021 12:56 UTC](https://discourse.nodered.org/t/parse-a-random-json/43085/1 "2021-03-23T12:56:00Z")

</div>

Hi,

When i do a http get from my solaredge system, i get a json array with types and values.  
But the types are on random object places, how can i parse them ?

 ![screen](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fca8f866e491b10014b02d92bdb6cb7e81606cb5.png)

---

<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:** [23 March 2021 13:04 UTC](https://discourse.nodered.org/t/parse-a-random-json/43085/2 "2021-03-23T13:04:51Z")

</div>

2 things needed to help you...

1. What is the structure of the output you expect after re-arraning the data?
2. Paste a sample of data (screenshots cannot be copied into a flow)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/7/17bff5dc13971a35d0ec5af2a1e2f6e73c6ce7fe.png)

And paste the value between backticks  
`````  
`[paste the json copied from the payload like this]`  
`````

---

<div class="post-metadata">

**Author:** ![Napster](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@Napster](https://discourse.nodered.org/u/Napster)\
**Post date:** [23 March 2021 13:17 UTC](https://discourse.nodered.org/t/parse-a-random-json/43085/3 "2021-03-23T13:17:00Z")

</div>

{"energyDetails":{"timeUnit":"DAY","unit":"Wh","meters":[{"type":"SelfConsumption","values":[{"date":"2021-03-23 00:00:00","value":6127}]},{"type":"Purchased","values":[{"date":"2021-03-23 00:00:00","value":3353}]},{"type":"FeedIn","values":[{"date":"2021-03-23 00:00:00","value":7555}]},{"type":"Production","values":[{"date":"2021-03-23 00:00:00","value":13682}]},{"type":"Consumption","values":[{"date":"2021-03-23 00:00:00","value":9480}]}]}}

I need the value of each type.

Thanks...

---

<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:** [23 March 2021 13:48 UTC](https://discourse.nodered.org/t/parse-a-random-json/43085/4 "2021-03-23T13:48:35Z")

</div>

Hi, try this jsonata expression in a change node

```auto
payload.energyDetails.meters.${type: values[*].value}

```

```auto
[{"id":"d49226ac.7ebd","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"energyDetails\":{\"timeUnit\":\"DAY\",\"unit\":\"Wh\",\"meters\":[{\"type\":\"SelfConsumption\",\"values\":[{\"date\":\"2021-03-23 00:00:00\",\"value\":6127}]},{\"type\":\"Purchased\",\"values\":[{\"date\":\"2021-03-23 00:00:00\",\"value\":3353}]},{\"type\":\"FeedIn\",\"values\":[{\"date\":\"2021-03-23 00:00:00\",\"value\":7555}]},{\"type\":\"Production\",\"values\":[{\"date\":\"2021-03-23 00:00:00\",\"value\":13682}]},{\"type\":\"Consumption\",\"values\":[{\"date\":\"2021-03-23 00:00:00\",\"value\":9480}]}]}}","payloadType":"json","x":120,"y":3140,"wires":[["23fa069.a74dd7a"]]},{"id":"23fa069.a74dd7a","type":"change","z":"5a245aa1.510164","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.energyDetails.meters.${type: values[*].value}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":3160,"wires":[["f396fc64.ed7c2"]]},{"id":"f396fc64.ed7c2","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":3180,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Napster](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@Napster](https://discourse.nodered.org/u/Napster)\
**Post date:** [23 March 2021 14:09 UTC](https://discourse.nodered.org/t/parse-a-random-json/43085/5 "2021-03-23T14:09:46Z")

</div>

Thanks !!

---

<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:** [6 April 2021 14:10 UTC](https://discourse.nodered.org/t/parse-a-random-json/43085/6 "2021-04-06T14:10:01Z")

</div>

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