Skip to main content
Solved

Nested JSON array to SQL table

  • October 3, 2018
  • 5 replies
  • 253 views

ayraju
Contributor
Forum|alt.badge.img+1

I am using FME to extract API data and pull the JSON string into a SQL table. I am able to work with most of the tables but there are a couple of them that are nested and am having trouble getting to format properly.

I have attached how the results need to look and sample of the JSON results

I tried using JSON Fragmenter but i cannot get the results. Can someone advise the best way to get this.

Best answer by takashi

Hi @ayraju, basically you can use multiple JSONFragmenters to extract every content from each level in a nested JSON document.

However, according to the desired result table shown in your screenshot, the requirement is to extract keys of the JSON "fields" objects in the lowest level as attribute values. This isn't usual JSON flattening operation.

I would provide two different approaches to resolve the special requirement. One is using regular expression (StringSearcher), another is using XQuery (JSONiq extension) expression (XMLXQueryExtractor).

See these workspace examples. Both are created with FME 2018.1.0.2.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

mygis
Supporter
Forum|alt.badge.img+14
  • Supporter
  • 307 replies
  • October 4, 2018
Hi @ayraju can you share the link with us if it is public?

 


takashi
Celebrity
  • 7843 replies
  • Best Answer
  • October 4, 2018

Hi @ayraju, basically you can use multiple JSONFragmenters to extract every content from each level in a nested JSON document.

However, according to the desired result table shown in your screenshot, the requirement is to extract keys of the JSON "fields" objects in the lowest level as attribute values. This isn't usual JSON flattening operation.

I would provide two different approaches to resolve the special requirement. One is using regular expression (StringSearcher), another is using XQuery (JSONiq extension) expression (XMLXQueryExtractor).

See these workspace examples. Both are created with FME 2018.1.0.2.


ayraju
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • 4 replies
  • October 4, 2018

Hi @ayraju, basically you can use multiple JSONFragmenters to extract every content from each level in a nested JSON document.

However, according to the desired result table shown in your screenshot, the requirement is to extract keys of the JSON "fields" objects in the lowest level as attribute values. This isn't usual JSON flattening operation.

I would provide two different approaches to resolve the special requirement. One is using regular expression (StringSearcher), another is using XQuery (JSONiq extension) expression (XMLXQueryExtractor).

See these workspace examples. Both are created with FME 2018.1.0.2.

Wow, you are amazing. This is great. Thank you so much!

 

 


f.kemminje
Contributor
Forum|alt.badge.img+11
  • Contributor
  • 189 replies
  • May 28, 2019

@takashi I was just going thru the answers for my current Question, i got your answer . similar to this answer.

what if the json objects are dynamic. i mean if the geometry objects(geojson) and stored in nested arrays. and json query string is different for each geometry. in my case there are many geometries are stored inside json file. and not in one location, all are in different nested arrays.

How can we extract all the geometries from different nested arrays?


nampreetatsafe
Safer
Forum|alt.badge.img+13

@takashi I was just going thru the answers for my current Question, i got your answer . similar to this answer.

what if the json objects are dynamic. i mean if the geometry objects(geojson) and stored in nested arrays. and json query string is different for each geometry. in my case there are many geometries are stored inside json file. and not in one location, all are in different nested arrays.

How can we extract all the geometries from different nested arrays?

FYI: An answer to @fkemminje's question was provided here: