Published on InterSystems Developer Community (https://community.intersystems.com)

Home > How can I convert CSV to JSON

Question
Galena Teneva · Jul 5, 2018

How can I convert CSV to JSON

Hi,
it is possible to convert a csv file to json file?

I want to stream json files and output the data as it comes in from the files. So my files are "csv" type and I want to convert these files to "json" type.


I can read csv file as follows:

ClassMethod ReadFile()
{
    set stream = ##class(%Stream.FileCharacter).%New()
    set sc = stream.LinkToFile("*.csv")
    do stream.Rewind()
    while'stream.AtEnd {
        set line=stream.ReadLine()
        write line,!
}

What should I add to convert it to "json" and read it again?

Thank you

#Beginner #CSV #ObjectScript #InterSystems IRIS

Source URL:https://community.intersystems.com/post/how-can-i-convert-csv-json