# Represent a JSON in a table and create a CSV file

**URL:** https://discourse.nodered.org/t/represent-a-json-in-a-table-and-create-a-csv-file/63331
**Category:** General
**Tags:** function-node, editable-list, dashboard, chart
**Created:** [31 May 2022 22:14 UTC](https://discourse.nodered.org/t/represent-a-json-in-a-table-and-create-a-csv-file/63331 "2022-05-31T22:14:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![DemalCal96](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@DemalCal96](https://discourse.nodered.org/u/DemalCal96)
#### Post date: [31 May 2022 22:14 UTC](https://discourse.nodered.org/t/represent-a-json-in-a-table-and-create-a-csv-file/63331/1 "2022-05-31T22:14:30Z")

</div>

Hello. I currently have a JSON that has the following structure:

mobj={1356895650000:{temp1:23, temp2:25,temp3:45,temp4:12},  
1356895680000:{temp1:14, temp2:24,temp3:25,temp4:16},  
1356895710000:{temp1:13, temp2:22,temp3:15,temp4:28},  
....}

what I need is to represent this in a table in the following way:

Time /temp1 /temp2 /temp3 /temp4  
1356895650000 23 25 45 12  
1356896580000 14 24 25 16  
1356895710000 13 22 15 28

Also, I want to export this data in CSV format, being able to visualize the data in the same way.  
Right now I'm using the CSV node, but I'm obtaining this

 ![cc](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/0609cb8e69c3c479fd356833aafc16ea213a8695.png)

---

<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: [31 May 2022 22:43 UTC](https://discourse.nodered.org/t/represent-a-json-in-a-table-and-create-a-csv-file/63331/2 "2022-05-31T22:43:53Z")

</div>

You need to create an array of objects.  
Something like this.

```auto
[{"id":"d50e160a0f210ab9","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"{\"1356895650000\":{\"temp1\":23,\"temp2\":25,\"temp3\":45,\"temp4\":12},\"1356895680000\":{\"temp1\":14,\"temp2\":24,\"temp3\":25,\"temp4\":16}}","payloadType":"json","x":110,"y":1880,"wires":[["75662bbb.02ab1c"]]},{"id":"75662bbb.02ab1c","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$each($$.payload, function ($v, $k){\t $merge([{\"Time\": $k}, $v])\t})","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1880,"wires":[["7dc1e1fa.49b8b8","3551e8a9.cc3b6"]]},{"id":"7dc1e1fa.49b8b8","type":"csv","z":"bf9e1e33.030598","name":"","sep":",","hdrin":"","hdrout":"all","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":530,"y":1880,"wires":[["6160bb0b377e4cac"]]},{"id":"3551e8a9.cc3b6","type":"ui_table","z":"bf9e1e33.030598","group":"8b5cde76.edd58","name":"","order":2,"width":0,"height":0,"columns":[],"outputs":0,"cts":false,"x":530,"y":1940,"wires":[]},{"id":"6160bb0b377e4cac","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":660,"y":1880,"wires":[]},{"id":"8b5cde76.edd58","type":"ui_group","name":"default","tab":"8f03e639.85956","order":1,"disp":false,"width":"12","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

```

You can then feed the array into the csv node and ui-table node.

---

<div class="post-metadata">

### Author: ![DemalCal96](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@DemalCal96](https://discourse.nodered.org/u/DemalCal96)
#### Post date: [1 June 2022 19:40 UTC](https://discourse.nodered.org/t/represent-a-json-in-a-table-and-create-a-csv-file/63331/3 "2022-06-01T19:40:35Z")

</div>

Thank you for your answer, it was the solution! I make the same with a function node but your way is faster!!! Maybe do you know how can I represente the timestamp as "human date"?

---

<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: [1 June 2022 19:55 UTC](https://discourse.nodered.org/t/represent-a-json-in-a-table-and-create-a-csv-file/63331/4 "2022-06-01T19:55:37Z")

</div>

```auto
$each($$.payload, function ($v, $k){
       $merge([{"Time": $fromMillis($number($k))}, $v])
})

or

$each($$.payload, function ($v, $k){
       $merge([{"Time": $moment($number($k)).format("DD/MM/yyyy HH:mm:ss")}, $v])
})

```

---

<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: [15 June 2022 19:55 UTC](https://discourse.nodered.org/t/represent-a-json-in-a-table-and-create-a-csv-file/63331/5 "2022-06-15T19:55:37Z")

</div>

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