Skip to main content
Solved

Json attributes extraction

  • July 27, 2018
  • 5 replies
  • 561 views

boubcher
Contributor
Forum|alt.badge.img+11

How to extract the attribute from the Json file , with the content

I trauied all Json transformer but did give me what I am looking for

Json content

[{"code":"EPSG:4326"},{"x":"41.86306379123165","y":"19.05070466974152"},{"x":"41.86136208513543","y":"19.048743553071773"},{"x":"41.8575815484205","y":"19.05212744890353"},{"x":"41.86306379123165","y":"19.05070466974152"}]

we want this

Best answer by daveatsafe

Hi @boubcher,

You can use the JSONFragmenter to break up the JSON records, and flatten into feature attributes. Then you can separate the code record and apply it the following locations using a VariableSetter and VariableRetriever.

flattenjson.fmw

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

geosander
Forum|alt.badge.img+7
  • 327 replies
  • July 27, 2018

If that is what you need, and you have write access to the JSON document, you might consider restructuring your JSON, because this reeks of bad data modeling (sorry). It will be a whole lot easier to read/transform!


danilo_fme
Celebrity
Forum|alt.badge.img+51
  • Celebrity
  • 2077 replies
  • July 27, 2018

Hi @boubcher

I simulated here in my Workspace with some transformers:

Results in FME Data Inspector:

Attached the Workspace - workspace-json.fmw

Thanks,

Danilo


daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • 1637 replies
  • Best Answer
  • July 27, 2018

Hi @boubcher,

You can use the JSONFragmenter to break up the JSON records, and flatten into feature attributes. Then you can separate the code record and apply it the following locations using a VariableSetter and VariableRetriever.

flattenjson.fmw


boubcher
Contributor
Forum|alt.badge.img+11
  • Author
  • Contributor
  • 212 replies
  • July 28, 2018

Hi @boubcher,

You can use the JSONFragmenter to break up the JSON records, and flatten into feature attributes. Then you can separate the code record and apply it the following locations using a VariableSetter and VariableRetriever.

flattenjson.fmw

the variable setter and retriever transformer are great

 

I can used them in many cases I have

 

Thanks

 


takashi
Celebrity
  • 7843 replies
  • July 29, 2018

Another thought. This workflow reconstructs the JSON document then fragments/flattens that. 

Template Expression in the JSONTemplater: Assuming the the input feature has an attribute called "_json_doc" which stores the original JSON document.

[
    let $m := fme:get-json-attribute('_json_doc')
    for $i in (2 to jn:size($m))
    return { "code" : $m(1)("code"), "x" : $m($i)("x"), "y" : $m($i)("y") }
]

0684Q00000ArL1aQAF.png