Skip to main content
Question

http caller and splitting returned Json into attributes.


Forum|alt.badge.img

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

erik_jan
Contributor
Forum|alt.badge.img+18
  • Contributor
  • April 14, 2020

Have a look at the JSONFlattener transformer.

That one is meant for these cases.

Hope this helps.


Forum|alt.badge.img
  • Author
  • April 14, 2020

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

 


erik_jan
Contributor
Forum|alt.badge.img+18
  • Contributor
  • April 14, 2020
qmangaming wrote:

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.


Forum|alt.badge.img
  • Author
  • April 14, 2020
erik_jan wrote:

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


nielsgerrits
VIP
Forum|alt.badge.img+54

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


nielsgerrits
VIP
Forum|alt.badge.img+54
qmangaming wrote:

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.


Forum|alt.badge.img
  • Author
  • April 14, 2020
nielsgerrits wrote:

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.


nielsgerrits
VIP
Forum|alt.badge.img+54
qmangaming wrote:

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.


virtualcitymatt
Celebrity
Forum|alt.badge.img+39
qmangaming wrote:

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.

nielsgerrits
VIP
Forum|alt.badge.img+54
virtualcitymatt wrote:

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.


virtualcitymatt
Celebrity
Forum|alt.badge.img+39
nielsgerrits wrote:

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!


mark2atsafe
Safer
Forum|alt.badge.img+46
  • Safer
  • April 14, 2020

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings