Skip to main content
Solved

Extracting values from JSON objects in JSONTemplater

  • January 16, 2026
  • 6 replies
  • 87 views

bruceharold
Supporter
Forum|alt.badge.img+19

I’m having trouble finding examples for JSONTemplater when working with a JSON array input attribute.

The incoming data looks like this:

{"layers": [
{
"defaultVisibility": true,
"geometryType": "esriGeometryPolygon",
"id": 1,
"maxScale": 0,
"minScale": 0,
"name": "Parcels",
"parentLayerId": -1,
"subLayerIds": null,
"type": "Feature Layer"
}
]}

I’m interested in extracting the first array member id value into an object like this:

{"layers": [{"id": 1}]}

I can almost get the data into what I want in two steps, first extracting the value with a query json["layers"][0]["id"] and then using the JSONTemplater to use the id value, but bizarrely the value 1 is cast to string “1” byt the templater, which is invalid for downstream work.

Anyone know how to make what I want in one step with JSONTemplater?  Thanks.

Best answer by debbiatsafe

Hello ​@bruceharold,

You can use the following template in the JSONTemplater given the incoming JSON data is stored in an attribute named input:

{
"layers" : [
{
let $firstArrObj := fme:get-json-attribute("input")("layers")(1)
return {"id": $firstArrObj("id")}
}
],
"exportContingentValues":true
}

This should produce the output you want using only the JSONTemplater.

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

ebygomm
Influencer
Forum|alt.badge.img+46
  • Influencer
  • January 16, 2026

I don’t know the answer to your first question but if you don’t want quotes in the json templater you can do something like this

xs:int(fme:get-attribute("id"))

 


cfvonner
Supporter
Forum|alt.badge.img+25
  • Supporter
  • January 16, 2026

@bruceharold Can you share what you have in the JSONTemplater?


bruceharold
Supporter
Forum|alt.badge.img+19
  • Author
  • Supporter
  • January 16, 2026

I don’t know the answer to your first question but if you don’t want quotes in the json templater you can do something like this

xs:int(fme:get-attribute("id"))

 

Thank you!  As the JSON I want is very simple I’m using JSONExtractor and ExpressionEvaluator to get what I need but it would be good to find the canonical way.


bruceharold
Supporter
Forum|alt.badge.img+19
  • Author
  • Supporter
  • January 16, 2026

@bruceharold Can you share what you have in the JSONTemplater?

I’ve temporarily abandoned a JSONTemplater but it was (after extracting the id value into it’s own attribute):

{
  "layers": [{"id": fme:get-attribute("layerId")}],
  "exportContingentValues":true
}


debbiatsafe
Safer
Forum|alt.badge.img+21
  • Safer
  • Best Answer
  • January 19, 2026

Hello ​@bruceharold,

You can use the following template in the JSONTemplater given the incoming JSON data is stored in an attribute named input:

{
"layers" : [
{
let $firstArrObj := fme:get-json-attribute("input")("layers")(1)
return {"id": $firstArrObj("id")}
}
],
"exportContingentValues":true
}

This should produce the output you want using only the JSONTemplater.


bruceharold
Supporter
Forum|alt.badge.img+19
  • Author
  • Supporter
  • January 20, 2026

Thanks Debbie, but if I had to guess I would say the number of people who could get there from the doc is vanishingly small! 😉This might be a good place for some AI assistance if enough XQuery material is out on the web.