Question
· Mar 5

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
Discussion (6)3
Log in or sign up to continue

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