Skip to main content
Solved

Json attributes extraction

  • Jul 27, 2018 3:27 PM UTC
  • 5 replies
  • 666 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

View original
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
  • Jul 27, 2018 3:33 PM UTC

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+58
  • Celebrity
  • Jul 27, 2018 3:46 PM UTC

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+24
  • Safer
  • Best Answer
  • Jul 27, 2018 3:58 PM UTC

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
  • Jul 28, 2018 6:06 PM UTC

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
  • Jul 29, 2018 8:54 AM UTC

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