Skip to main content
Solved

JSONTemplater single element arrays

  • November 3, 2021
  • 1 reply
  • 37 views

jdh
Contributor
Forum|alt.badge.img+37
  • Contributor
  • 2002 replies

I'm using the JSONTemplater and have an attribute list.

 My (sub) template is

 {
"id": fme:get-attribute("sumo_id"),
 "crosswalks": fme:get-list-attribute("_list{}.poly_id")
 }

Which works fine if i have multiple list elements,  but becomes a string if I only have one.

 

{

    "id": "390335938",

    "crosswalks": ["225790", "2833648", "15808"]

  }, {

    "id": "126630292",

    "crosswalks": "1243410"

  }

 

when I'm looking for

 

{

    "id": "390335938",

    "crosswalks": ["225790", "2833648", "15808"]

  }, {

    "id": "126630292",

    "crosswalks": ["1243410"]

  },

 

Is there anyway to force the JSONTemplater to keep the array, or baring that what is the best way to post process the templater results?

Best answer by daveatsafe

Hi @jdh​,

 

If you enclose the fme:get-list_attribute function in square braces, it will force the array creation for lists with only one entry.

{
"id": fme:get-attribute("sumo_id"),
 "crosswalks": [fme:get-list-attribute("_list{}.poly_id")]
 }

 

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.

1 reply

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • 1637 replies
  • Best Answer
  • November 3, 2021

Hi @jdh​,

 

If you enclose the fme:get-list_attribute function in square braces, it will force the array creation for lists with only one entry.

{
"id": fme:get-attribute("sumo_id"),
 "crosswalks": [fme:get-list-attribute("_list{}.poly_id")]
 }