Skip to main content
Solved

JSON - packing arrays on Templater.


jorge_vidinha
Contributor
Forum|alt.badge.img+2

I'm trying to pack 2 simple valid arrays of objects in an json object inside a Templater.

Happens that out of the templater my result seems to get interpreted as a string addin some strange characters  \n   {\n

May i be missing some json logic here ? thanks 

array_1

[
   {
      "att1" : "DUT",
      "att2" : null
   }
]

array_2

 [{
      "att1" : "DUT",
      "att2" : null
   },
{
      "att1" : "DUT",
      "att2" : null
 }]


Object packed at Templater with expression:

 {
      "array_1" : fme:get-attribute("array_1"),
      "array_2" : fme:get-attribute("array_2")
 }

Result

{ "array_1" : "[\n   {\n      \"att1\" : \"DUT\",\n      \"att2\" : null\n   }\n]", "array_2" : " [{\n      \"att1\" : \"DUT\",\n      \"att2\" : null\n   },\n{\n      \"att1\" : \"DUT\",\n      \"att2\" : null\n }]\n" }

Best answer by takashi

Hi @jorge_vidinha, the reason is that you are using get-attribute function though the attribute values are JSON objects. Try using get-json-attribute function instead.

View original
Did this help you find an answer to your question?

2 replies

takashi
Evangelist
  • Best Answer
  • June 24, 2016

Hi @jorge_vidinha, the reason is that you are using get-attribute function though the attribute values are JSON objects. Try using get-json-attribute function instead.


jorge_vidinha
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • June 24, 2016
takashi wrote:

Hi @jorge_vidinha, the reason is that you are using get-attribute function though the attribute values are JSON objects. Try using get-json-attribute function instead.

Mr. Takashi. Thank you !.

You have solved me the json challenge puzzle. Let the fme votings of the day be with you.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings