# Convert JSON Array to CSV

**URL:** <https://forum.uipath.com/t/convert-json-array-to-csv/452724>\
**Category:** Activities\
**Tags:** question, webapi, activities\
**Created:** [June 30, 2022, 11:21am UTC](https://forum.uipath.com/t/convert-json-array-to-csv/452724 "2022-06-30T11:21:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmorgan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rmorgan/32/182263_2.png) [@rmorgan](https://forum.uipath.com/u/rmorgan)\
**Post date:** [June 30, 2022, 11:21am UTC](https://forum.uipath.com/t/convert-json-array-to-csv/452724/1 "2022-06-30T11:21:39Z")

</div>

Ive done this before

I have the attached JSON Array and when using the activity JSON to CSV gives  
Json to CSV: Object reference not set to an instance of an object.

[PW43\_4.txt](https://forum.uipath.com/uploads/short-url/cSLtruOBXIgyKjsuhQmEA5Yh4GI.txt) (7.2 KB)

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [June 30, 2022, 11:31am UTC](https://forum.uipath.com/t/convert-json-array-to-csv/452724/2 "2022-06-30T11:31:25Z")

</div>

just ensure the surrounding { } or add it when it is missing  
 ![grafik](https://global.discourse-cdn.com/uipath/original/4X/8/e/8/8e828b1491d5aca3c114903baf7dece64b02bd71.png)

As an alternate we can do:

 ![grafik](https://global.discourse-cdn.com/uipath/original/4X/a/5/b/a5b51cd859c471299518320ae04533acf84c0e17.jpeg)  
 ![grafik](https://global.discourse-cdn.com/uipath/original/4X/5/e/b/5eb4bed29db0dbf499ef2d87bde2d073c992372b.png)  
`JsonConvert.DeserializeObject(Of DataTable)(myJObject("Result").tostring)`

we convert the JSON to a datatable and can use e.g. the write CSV file activity later

---

<div class="post-metadata">

**Author:** ![rmorgan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rmorgan/32/182263_2.png) [@rmorgan](https://forum.uipath.com/u/rmorgan)\
**Post date:** [June 30, 2022, 11:50am UTC](https://forum.uipath.com/t/convert-json-array-to-csv/452724/3 "2022-06-30T11:50:15Z")

</div>

I may have to ask you to expand slightly on your solution, my knowledge of JSON etc is pretty poor to be honest, ☹

I have fixed the input file and added the surrounding {}

Read the Text File

Deserialised it into an Array

but can’t get any further

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [June 30, 2022, 11:53am UTC](https://forum.uipath.com/t/convert-json-array-to-csv/452724/4 "2022-06-30T11:53:47Z")

</div>

first very important thing is that you check that the JSON is surrounded with { } (in your txt it was missing / invalid JSON string)

the Result property value is the JSON representation of a datatable. So were able to use for a deserialization and can convert from this JSON string the corresponding Datatable

Ensure following:  
 ![grafik](https://global.discourse-cdn.com/uipath/original/4X/6/1/9/6194ddd4ee4852f06cc14c4fead5b53d7c6d7337.png)

Create a variable: dtResult | Datatype: DataTable

Just use an assign acitvity

```auto
dtResult = JsonConvert.DeserializeObject(Of DataTable)(yourDeserializeJSONOutputVar("Result").tostring)

```

---

<div class="post-metadata">

**Author:** ![rmorgan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rmorgan/32/182263_2.png) [@rmorgan](https://forum.uipath.com/u/rmorgan)\
**Post date:** [June 30, 2022, 12:03pm UTC](https://forum.uipath.com/t/convert-json-array-to-csv/452724/5 "2022-06-30T12:03:36Z")

</div>

Amazing thankyou, this will save the office so much time 🙂

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [July 3, 2022, 12:04pm UTC](https://forum.uipath.com/t/convert-json-array-to-csv/452724/6 "2022-07-03T12:04:26Z")

</div>

Closed on July 3, 2022, 12:04pm UTC

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