Skip to main content
Solved

JSON support using JSONTemplater

  • August 29, 2017
  • 6 replies
  • 75 views

jorge_rosales
Contributor
Forum|alt.badge.img+8

I am trying to generate a JSON file that includes elements like this one:

But I have problems with the "positions" property. I can´t reproduce it. I can get and array ([] instead of {}) and each element like "9": [220000, 3230000] with non desired {} at the begining and the end.

I attach the full project () with the target.json that I need.

Thanks in advance.

Best answer by juanchuchow

Hi,

Try changing the value for the "positions" key in la ISLA subtemplate to this:

-----------------------

"positions": {| fme:process-features("POSITIONS", "id_isla", fme:get-attribute("id")) |}

-----------------------

Notice "|" in wrapping "{|" and "|}". "{| |}" is a merge constructor, used to merge several objects.

I ran your workspace with the "{| |}" change, instead of an array of objects you'll get a single merge object.

Hope this helps.

Juan

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.

6 replies

geosander
Forum|alt.badge.img+7
  • 327 replies
  • August 29, 2017

Ah yes... it's a royal pain to insert key-value pairs from features into an object. Arrays/lists are easy though... And if you omit the {} in your POSITIONS sub-template, the JSONTemplater throws an error - I wish it would allow for text in the JSONTemplater window without enclosing {} as long as the whole resulting document proves to be valid JSON!

 

I have been struggling with this before and ended up creating the objects with a PythonCaller and the JSON library...


juanchuchow
Safer
Forum|alt.badge.img+1
  • Safer
  • 12 replies
  • Best Answer
  • August 29, 2017

Hi,

Try changing the value for the "positions" key in la ISLA subtemplate to this:

-----------------------

"positions": {| fme:process-features("POSITIONS", "id_isla", fme:get-attribute("id")) |}

-----------------------

Notice "|" in wrapping "{|" and "|}". "{| |}" is a merge constructor, used to merge several objects.

I ran your workspace with the "{| |}" change, instead of an array of objects you'll get a single merge object.

Hope this helps.

Juan


geosander
Forum|alt.badge.img+7
  • 327 replies
  • August 29, 2017

Hi,

Try changing the value for the "positions" key in la ISLA subtemplate to this:

-----------------------

"positions": {| fme:process-features("POSITIONS", "id_isla", fme:get-attribute("id")) |}

-----------------------

Notice "|" in wrapping "{|" and "|}". "{| |}" is a merge constructor, used to merge several objects.

I ran your workspace with the "{| |}" change, instead of an array of objects you'll get a single merge object.

Hope this helps.

Juan

Wow, that is a nice trick @juanchuchow1323! Never knew that the | (pipe) thing works like that in the JSONTemplater, so I'm glad I learned something new today! :) Wish I knew about this sooner... would have saved me a lot of work...

 

 

@j4 or @TiaAtSafe: please mark Juan's reply as the correct answer, so other people can find this too!

danilo_fme
Celebrity
Forum|alt.badge.img+51
  • Celebrity
  • 2077 replies
  • August 29, 2017

Hi,

Try changing the value for the "positions" key in la ISLA subtemplate to this:

-----------------------

"positions": {| fme:process-features("POSITIONS", "id_isla", fme:get-attribute("id")) |}

-----------------------

Notice "|" in wrapping "{|" and "|}". "{| |}" is a merge constructor, used to merge several objects.

I ran your workspace with the "{| |}" change, instead of an array of objects you'll get a single merge object.

Hope this helps.

Juan

Great @juanchuchow1323

 


takashi
Celebrity
  • 7843 replies
  • August 30, 2017

Hi,

Try changing the value for the "positions" key in la ISLA subtemplate to this:

-----------------------

"positions": {| fme:process-features("POSITIONS", "id_isla", fme:get-attribute("id")) |}

-----------------------

Notice "|" in wrapping "{|" and "|}". "{| |}" is a merge constructor, used to merge several objects.

I ran your workspace with the "{| |}" change, instead of an array of objects you'll get a single merge object.

Hope this helps.

Juan

@juanchuchow1323, thanks for sharing the tip.

 

There are only few resources about JSONiq on the Web. I finally found this one.

 

JSONiq Extension to XQuery 1.0 > 4.2. Object Constructors (Example 4.3. Dynamically building an object)

 


jorge_rosales
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • 44 replies
  • August 30, 2017

Hi,

Try changing the value for the "positions" key in la ISLA subtemplate to this:

-----------------------

"positions": {| fme:process-features("POSITIONS", "id_isla", fme:get-attribute("id")) |}

-----------------------

Notice "|" in wrapping "{|" and "|}". "{| |}" is a merge constructor, used to merge several objects.

I ran your workspace with the "{| |}" change, instead of an array of objects you'll get a single merge object.

Hope this helps.

Juan

It works perfectly! @juanchuchow1323 thanks a lot for the tip.