Question

http caller and splitting returned Json into attributes.


Badge

Hi all, i am currently downloading a large json body via http caller and i need to split the returned json body into attributes. see below:

the returned json body contains many results (one of which is shown in the below image) which i need to breakup into "clientrefid" with the related fields which then i need to get the ID attriubte returned so i can the use that in the next http caller.


12 replies

Userlevel 2
Badge +12

Have a look at the JSONFlattener transformer.

That one is meant for these cases.

Hope this helps.

Badge

HI thank you for your response. when i try to expose 'clientRefId" i get a <missing> value. am i missing something here?

 

Userlevel 2
Badge +12

HI thank you for your response. when i try to expose 'clientRefId" i get a <missing> value. am i missing something here?

 

Try exposing Out_clientRefId as that will be the new attribute name, since you ask to prefix the attribute.

Badge

Try exposing Out_clientRefId as that will be the new attribute name, since you ask to prefix the attribute.

HI, i have tried that and still the attribute is coming out empty.

 

Thank you

Userlevel 6
Badge +31

Connect an inspector to the outputport and analyze the result there for clues in the FME Data Inspector.

If you have one outputfeature with multiple id values in a list:

You probably need to fragment it first, to split the one block of json in several features. Then flatten the attributes:

Added sample workspace template (2020): sample_workbench.fmwt

Userlevel 6
Badge +31

HI thank you for your response. when i try to expose 'clientRefId" i get a <missing> value. am i missing something here?

 

You probably need to fragment it first, to split the one block of json in several features, then flatten the attributes. Connect an inspector to the outputport and analyze the result there for clues.

Badge

Connect an inspector to the outputport and analyze the result there for clues in the FME Data Inspector.

If you have one outputfeature with multiple id values in a list:

You probably need to fragment it first, to split the one block of json in several features. Then flatten the attributes:

Added sample workspace template (2020): sample_workbench.fmwt

Thank you nielsgerrits , i followed your example and many others today and i am still not able to break down the json. i am starting to wonder if this json (from another company data portal) is either corrupt or unusable. is it at all possible to send the json to you to look at? i am new to json so i am feeling somewhat lost.

Userlevel 6
Badge +31

Thank you nielsgerrits , i followed your example and many others today and i am still not able to break down the json. i am starting to wonder if this json (from another company data portal) is either corrupt or unusable. is it at all possible to send the json to you to look at? i am new to json so i am feeling somewhat lost.

Sure, send it and I'll have a look.

Userlevel 4
Badge +26

Thank you nielsgerrits , i followed your example and many others today and i am still not able to break down the json. i am starting to wonder if this json (from another company data portal) is either corrupt or unusable. is it at all possible to send the json to you to look at? i am new to json so i am feeling somewhat lost.

Definitely inspector is a good option here to see how the data looks after the JSONFlattner. You can also try turning on "Recursively Flatten Objects" to see if that helps. JSON is annoying at first but gets easier to work with.

 

See if you can see anything in the Feature Information Window that realstes to ClientRefId. (it might have a "." Character before it)

 

If the JSON was corrupt or invalid the the JSONFlattener would reject the data.
Userlevel 6
Badge +31

Definitely inspector is a good option here to see how the data looks after the JSONFlattner. You can also try turning on "Recursively Flatten Objects" to see if that helps. JSON is annoying at first but gets easier to work with.

 

See if you can see anything in the Feature Information Window that realstes to ClientRefId. (it might have a "." Character before it)

 

If the JSON was corrupt or invalid the the JSONFlattener would reject the data.

I think parsing json is just difficult because there are endless combinations possible (data / objects / arrays) , so you really need to understand what you need and what the structure of the file is. When you only are looking for a certain value (succes is true or false) its plain easy. But when you need to read and process related structures it can be hard.

What helps for me is babysteps (this is almost always the solution when I get lost) instead of trying to do it all in once.

But the big help with JSON for me is to use a FeatureReader, point it to a file and being able to browse through the structure and having the paths generated.

Userlevel 4
Badge +26

I think parsing json is just difficult because there are endless combinations possible (data / objects / arrays) , so you really need to understand what you need and what the structure of the file is. When you only are looking for a certain value (succes is true or false) its plain easy. But when you need to read and process related structures it can be hard.

What helps for me is babysteps (this is almost always the solution when I get lost) instead of trying to do it all in once.

But the big help with JSON for me is to use a FeatureReader, point it to a file and being able to browse through the structure and having the paths generated.

Yes! this for me too! Always saving a response to a text file then using the reader to build the query when building a workspace. Very helpful!

Userlevel 4
Badge +25

Maybe this brief article will help?

https://knowledge.safe.com/questions/109319/question-of-the-week-flattening-nested-json-attrib.html

But as other folk have mentioned, the JSONFlattener or JSONFragmenter are the transformers you need.

Reply