CSV to JSON conversion

I have a CSV file format as shown below, which I need to convert it to JSON Object file format. Can someone help to solve this?

image

Thanks in Advance.

2 Likes

Hi @suvarnalaxmi

You can read this article for your reference.

cheers :smiley:

Happy learning :smiley:

1 Like

Hi @suvarnalaxmi,

  • Read the csv file into the datatable .
  • Use the below activity that can convert to json.

Regards
Balamurugan.S

Hi @pattyricarte, @balupad14

I want my JSON output to be in the format as {“Heap Memory”:25.38,“None Heap Memory”:38.55,“Heap Free Memory”:74.65}

but Am getting it as {“Heap Memory”:“25.38”,“None Heap Memory”:“38.55”,“Heap Free Memory”:“74.65”}

1 Like

Can i ask why you like the first format ? @suvarnalaxmi

I want my JSON output to be in the format as {“Heap Memory”:25.38,“None Heap Memory”:38.55,“Heap Free Memory”:74.65}

1 Like

Thanks @pattyricarte

I need to push these values to elastic search and generate graphs.

You should have columns of you datatable of some numeric type (e.g. int32)
You could achieve it by creating datatable matching the format of CSV using BuildDataTable activity before reading the CSV.

In such case the conversion into JSON will get desired result.

Cheers

Thanks @J0ska

I’ll work on this and let you konw.

you can use the find and replace

  1. from ”:“ to ”:
  2. from “,“ to ,

Regards
balamurugan.S

Actually ReadCSV always screw up dt definition
So you will need to use two data tables:
DT1 for reading from CSV - with data type defined by ReadCSV activity
DT2 for valid JSON output - declared with proper data types

and use the below code to copy from DT1 to DT2

DT2 = (From row In DT1.AsEnumerable
Select DT2.Rows.Add(row.item("item1"),row.item("item2"),row.item("item3"),row.item("item4"))).copytodatatable