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...
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
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!
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)
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.