Output Dynamic Object JSON Data To A CSV File
We have JSON type data in a Dynamic Object. Is there a simple way to export / dump that data to a delimited string or file?
e.g.
Results={"ClassA":{"ClassName":"ClassA","ACount":367191880,"BCount":367191880,"CurrentDiff":0,"PreviousDiff":0,"ReportDate":"2024-03-02 00:00:00"}
"ClassB":{"ClassName":"ClassB","ACount":5352149227,"BCount":5352149227,"CurrentDiff":0,"PreviousDiff":0,"ReportDate":"2024-03-02 00:00:00"}}
Comments
You can use embedded python:
Good idea. This might work:
ClassMethod HandleJSON()
{
S Results= {
"ClassA":{"ClassName":"ClassA","ACount":367191880,"BCount":367191880,"CurrentDiff":0,"PreviousDiff":0,"ReportDate":"2024-03-02 00:00:00"},
"ClassB":{"ClassName":"ClassB","ACount":5352149227,"BCount":5352149227,"CurrentDiff":0,"PreviousDiff":0,"ReportDate":"2024-03-02 00:00:00"}
}
w..GetCsv(Results.%ToJSON())
}
ClassMethod GetCsv(json As%String) As%String [ Language = python ]
{
import pandas
df = pandas.read_json(json, orient="index")
return df.to_csv(index=False)
}
Bingo!
@Carl (booz Allen) Deitrich
Did the solution of @Malte Schnack work for you?
@Luis Angel Pérez Ramos @Malte Schnack
Yes, it worked like a Charm! I can't thank you all enough.
I had to install Pandas on my local laptop, but our servers already had it installed. Now I'm off to start coding :)
💡 This question is considered a Key Question. More details here.