Skip to main content

Hi All,

I have a json templater which i’m using to create a json that has ‘firstname’ and ‘lastname’ - there’s 3 rows of data.

I created the following in the root template but it outputs the 3 separately:

{
       "firstName" : fme:get-attribute("first_name"),
       "lastName" : fme:get-attribute("last_name")
}
 

I then tried creating a sub template -with the following settings:

 

Here is the output I get:

{ "firstName" : "first2", "lastName" : "Last1" }{ "firstName" : "first2", "lastName" : "Last2" }{ "firstName" : "first3", "lastName" : "Last3" }

 

I can see that it’s missing an extra set of curly brackets, and when trying to run this result through a JSON validator it fails and gives this message:  “Unexpected non-whitespace characters were found after the JSON text”

 

I’ve looked at the JSON templater documentation and the exercise but I can’t seem to get this working.

Any help would be greatly appreciated

 

Many thanks,

 

Sam

This doesn’t answer your question directly, however, in this case I would use an AttributeCreator with an Aggregator to just build the document. 

JSONTemplator has a habit of complicated things.

What you are creating here though is more of a list of objects which is a little funny. Typically these would instead all be in an array. Although of course the don’t have to be. 
 

{
  “names” :
     {
        “firstName” : “Alice”,
        “lastName”: “Bloggs”
      },
        “firstName” : “Bob”,
        “lastName” : “Bloggs
      }
   ]

This is more the kind of thing the json template expects to produce.



 


Reply