# Extracting object elements from CSVs into graphable data

**URL:** <https://discourse.nodered.org/t/extracting-object-elements-from-csvs-into-graphable-data/23290>\
**Category:** General\
**Created:** [18 March 2020 20:43 UTC](https://discourse.nodered.org/t/extracting-object-elements-from-csvs-into-graphable-data/23290 "2020-03-18T20:43:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![firedude144](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@firedude144](https://discourse.nodered.org/u/firedude144)\
**Post date:** [18 March 2020 20:43 UTC](https://discourse.nodered.org/t/extracting-object-elements-from-csvs-into-graphable-data/23290/1 "2020-03-18T20:43:42Z")

</div>

I'm trying to build a graph that will update periodically from an open data source (the COVID-19 data from Our World in Data org (blob:[https://ourworldindata.org/f7778f11-7e49-4608-8695-c9c420e6e817](https://ourworldindata.org/f7778f11-7e49-4608-8695-c9c420e6e817)). I'm a seasoned programmer trying to learn JSON & Node Red -- it's not really making much sense to me,frankly.

The data comes in OK as a series of objects that look like this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/0/005d94ca5de63ac812e8413c192780e9d5f2b660.png)

The objects acquire more elements as the number of countries report, so I can't rely on the positions of the elements. In other words, Japan is the 3rd element of the list, but that will change when Canada gets added. I've tried various things none of which produced the expected results.

```auto
[{"id":"d6750951.024458","type":"debug","z":"32556e66.f0c022","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":260,"wires":[]},{"id":"a0a1bbdf.5bb7b8","type":"change","z":"32556e66.f0c022","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"\"China:\" & msg.payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":260,"wires":[["d6750951.024458"]]},{"id":"4003ded.07f7f2","type":"switch","z":"32556e66.f0c022","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"China","vt":"str"},{"t":"eq","v":"Canada","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":300,"wires":[["a0a1bbdf.5bb7b8"],["6286f841.150b38"]]},{"id":"bb1ddbbb.732d78","type":"function","z":"32556e66.f0c022","name":"","func":"\nvar parts = msg.payload;\nmsg.payload = parts;\nreturn msg;\n","outputs":1,"noerr":0,"x":450,"y":300,"wires":[["4003ded.07f7f2"]]},{"id":"6286f841.150b38","type":"change","z":"32556e66.f0c022","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":" msg.payload.concat(\"Canada\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":320,"wires":[["b07f7f00.16bfd"]]},{"id":"19ef5c8.f4157a4","type":"csv","z":"32556e66.f0c022","name":"","sep":",","hdrin":true,"hdrout":false,"multi":"one","ret":"\\n","temp":"date,World,Afghanistan,Albania,Algeria,Andorra,Antigua and Barbuda,Argentina,Armenia,Australia,Austria,Azerbaijan,Bahrain,Bangladesh,Belarus,Belgium,Bhutan,Bolivia,Bosnia and Herzegovina,Brazil,Brunei,Bulgaria,Burkina Faso,Cambodia,Cameroon,Canada,Cayman Islands,Chile,China,Colombia,Costa Rica,Cote d'Ivoire,Croatia,Cuba,Cyprus,Czech Republic,Democratic Republic of Congo,Denmark,Dominican Republic,Ecuador,Egypt,Estonia,Ethiopia,Faeroe Islands,Finland,France,French Guiana,French Polynesia,Gabon,Georgia,Germany,Ghana,Gibraltar,Greece,Guadeloupe,Guernsey,Guinea,Guyana,Honduras,Hungary,Iceland,India,Indonesia,International,Iran,Iraq,Ireland,Israel,Italy,Jamaica,Japan,Jersey,Jordan,Kenya,Kuwait,Latvia,Lebanon,Liechtenstein,Lithuania,Luxembourg,Macedonia,Malaysia,Maldives,Malta,Martinique,Mexico,Moldova,Monaco,Mongolia,Morocco,Nepal,Netherlands,New Zealand,Nigeria,Norway,Oman,Pakistan,Palestine,Panama,Paraguay,Peru,Philippines,Poland,Portugal,Puerto Rico,Qatar,Reunion,Romania,Russia,Saint Barthlemy,Saint Martin (French part),Saint Vincent and the Grenadines,San Marino,Saudi Arabia,Senegal,Serbia,Singapore,Slovakia,Slovenia,South Africa,South Korea,Spain,Sri Lanka,Sudan,Sweden,Switzerland,Thailand,Togo,Trinidad and Tobago,Tunisia,Turkey,Ukraine,United Arab Emirates,United Kingdom,United States,Vatican,Venezuela,Vietnam","skip":"0","strings":true,"x":310,"y":300,"wires":[["bb1ddbbb.732d78"]]},{"id":"b07f7f00.16bfd","type":"debug","z":"32556e66.f0c022","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":990,"y":320,"wires":[]},{"id":"d26871e7.693cd","type":"http request","z":"32556e66.f0c022","name":"Get COVID data","method":"GET","ret":"txt","paytoqs":false,"url":"https://covid.ourworldindata.org/data/total_cases.csv","tls":"","persist":false,"proxy":"","authType":"","x":140,"y":300,"wires":[["19ef5c8.f4157a4"]]},{"id":"300c2f1f.e165e","type":"inject","z":"32556e66.f0c022","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":240,"wires":[["d26871e7.693cd"]]}]\

```

Obviously I don't grasp some fundamental JSON concepts on how to refer to various parts of an object. Maybe someone can steer me to some docs that explain to me like I'm 5...

---

<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:** [18 March 2020 20:59 UTC](https://discourse.nodered.org/t/extracting-object-elements-from-csvs-into-graphable-data/23290/2 "2020-03-18T20:59:35Z")

</div>

That isn't JSON, it is a javascript object. JSON is always a string.  
To get the China value use `msg.payload.China` It is basically the same as the members of a C++ class for example. Have a look at the node-red guide [Working with Messages](https://nodered.org/docs/user-guide/messages) which you will probably find helpful. Also worth looking through the other docs and the examples in the cookbook.

---

<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:** [17 May 2020 20:59 UTC](https://discourse.nodered.org/t/extracting-object-elements-from-csvs-into-graphable-data/23290/3 "2020-05-17T20:59:36Z")

</div>

Closed on 17 May 2020 20:59 UTC

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