Parsing JSON Question

Five Stars

Parsing JSON Question

I have the following json response:

{
"2019-06-01":["recs": 1, "vals": 2],
"2019-06-02":["recs": 1, "vals": 2]
}

 

I want the result:

2019-06-01, 1, 2
2019-06-02, 1, 2

 

In the JSONPath I have "$.[*]"


I can get back the values 1,2, but I don't know how to get the date first?

 

I know it must be something stupid easy, but I've tried all sorts of combinations of things and still can't seem to get it!

 

TIA.

 

Frank

Tags (1)
Nine Stars

Re: Parsing JSON Question

It look's like the correct version of your json should be :

 

{
"2019-06-01":{"recs": 1, "vrec": 2},
"2019-06-02":{"recs": 1, "vals": 2}
}

Another issue is that, "2019-06-01" and "2019-06-02" are like column names, not values

 

Your expected result may require something like :

 

{
	"root":[
		{"date":"2019-06-01","recs": 1, "vals": 2},
	      {"date":"2019-06-02","recs": 1, "vals": 2}
	     ]
}

 

Regards
DGM
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Five Stars

Re: Parsing JSON Question

Yah, it's not my API so I don't have any control over it... I can get one day record at a time though, so I guess the best thing is to loop through the days I want data for and pass it as a context variable or something.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog