Skip to main content
Question

Extract JSON attributes with same name

  • February 20, 2018
  • 4 replies
  • 152 views

stefanh
Contributor
Forum|alt.badge.img+8

I am having trouble extracting all the information from a JSON. I have a JSON (see attached) with multiple addresses on the same level. When I use the JSON Flattener or the JSON fragmenter I only get the first address.

The JSON in the attachment contains for example a JSONFeature addresses with the subfeature type which can be "vestigingsadres" or "correspondentieadres".

This is just an example, same JSON I work with contain multiple addresses. And on forehand I do not know how many.

How can I extract this information?

4 replies

takashi
Influencer
  • February 20, 2018

Hi @stefanh, The JSON schema contains a list object called "items" and each "items" object contains sub list object called "addresses". If you apply the JSONFlattener to the document, the resulting feature will have this nested list attribute.

items{}.addresses{}.bagId
items{}.addresses{}.city
items{}.addresses{}.country
... and so on.

You can extract required elements from the list. Check the content of the list with Feature Information window in FME Data Inspector, after flattening the document with the JSONFlattenere.


stefanh
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • February 20, 2018
takashi wrote:

Hi @stefanh, The JSON schema contains a list object called "items" and each "items" object contains sub list object called "addresses". If you apply the JSONFlattener to the document, the resulting feature will have this nested list attribute.

items{}.addresses{}.bagId
items{}.addresses{}.city
items{}.addresses{}.country
... and so on.

You can extract required elements from the list. Check the content of the list with Feature Information window in FME Data Inspector, after flattening the document with the JSONFlattenere.

Hi @takashi thanks for the quick response. I implemented your suggestion and this works. See screenshot. 

 

However I do not always know how many addresses the JSON-document contains. Is there a way to extract all the address information without knowing the number of sub list objects?. 

 

So a more uniform way, instead of defining "addresses{0}.type" and "addresses{1}.type"

 

 

Hope this is possible

 

 

 

 


peteralstorp
Contributor
Forum|alt.badge.img+5
stefanh wrote:
Hi @takashi thanks for the quick response. I implemented your suggestion and this works. See screenshot.

 

However I do not always know how many addresses the JSON-document contains. Is there a way to extract all the address information without knowing the number of sub list objects?.

 

So a more uniform way, instead of defining "addresses{0}.type" and "addresses{1}.type"

 

 

Hope this is possible

 

 

 

 

Maybe this Q and A is relevant to you, stefanh?

 

 

https://knowledge.safe.com/questions/69497/decode-json.html?childToView=69498

 

 

 


itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • May 7, 2018
stefanh wrote:
Hi @takashi thanks for the quick response. I implemented your suggestion and this works. See screenshot.

 

However I do not always know how many addresses the JSON-document contains. Is there a way to extract all the address information without knowing the number of sub list objects?.

 

So a more uniform way, instead of defining "addresses{0}.type" and "addresses{1}.type"

 

 

Hope this is possible

 

 

 

 

Hoi @stefanh,

 

Have a look at the List Exploder transformer, to convert list elements into features.

 

Hope this helps,

 

Itay

 


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