Question Carl (booz Allen) Deitrich · Mar 5, 2024

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"}}

Product version: IRIS 2023.1
$ZV: IRIS for Windows (x86-64) 2023.1.2 (Build 450_0_22859U) Mon Dec 4 2023 14:21:33 EST

Comments

Malte Schnack  Mar 6, 2024 to Luis Angel Pérez Ramos

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)
}
0