Skip to main content

In the JSON transformer documentation, there is a sub-section on JSON Query, which states:

 

JSON Property Expressions

A property expression is a structure expression as described above, followed by a . (dot) operator and a property name. Currently, the only supported properties are type and size. The type property returns the type of the JSON value referred to by the JSON structure expression. For example, if the outermost JSON element is an array, and the first element of the array is a string, then the expression jsonn0].type would have a value of string. The size property, which can only be applied to an array, returns the number of elements in the array.

 

For the life of me, I cannot find any other documentation on this and am unable to get it working. I tried a similar example to the one described above ("columns" is an array) but I get the following error:

The JSON query 'jsono"columns"].size' cannot be used to produce features. String expressions and property expressions cannot be used in the query

 

Any thoughts? If it cannot be used in a query, then where and how can it be used? I would like to extract the size of the array without having to use a ListElementCounter right after. Thanks.

Which JSON transformer are you using? Are you trying to use it in the JSONFragmenter? I think that would give you that warning.

 

The following sort of query works for me in a JSONExtractor and returns the size of the array

json"details"]t"metadata"]p"country_of_origin"].size

 

 


Which JSON transformer are you using? Are you trying to use it in the JSONFragmenter? I think that would give you that warning.

 

The following sort of query works for me in a JSONExtractor and returns the size of the array

json"details"]t"metadata"]p"country_of_origin"].size

 

 

Hi @ebygomm​, mostly JSONFragmenter, but sometimes JSONExtractor and JSONFlattener as well. Same JSON Query question would apply though, no?


Hi @ebygomm​, mostly JSONFragmenter, but sometimes JSONExtractor and JSONFlattener as well. Same JSON Query question would apply though, no?

No, you can't use that query in a JSONFragmenter. I've just tried it and get the error message you've posted


Hi @ebygomm​, mostly JSONFragmenter, but sometimes JSONExtractor and JSONFlattener as well. Same JSON Query question would apply though, no?

Hmm thanks for testing. I wonder if this is a bug? I tend to use the fragmenter a lot because most of the json data I have to work with is filled with arrays and nested objects.


Hi @ebygomm​, mostly JSONFragmenter, but sometimes JSONExtractor and JSONFlattener as well. Same JSON Query question would apply though, no?

I think it makes sense that it doesn't work with a fragmenter tbh.


Hi @ebygomm​, mostly JSONFragmenter, but sometimes JSONExtractor and JSONFlattener as well. Same JSON Query question would apply though, no?

Thanks, I think I understand what you mean. A fragmenter is not meant to create new attributes but expose ones in the JSON document. With the Extractor, you're essentially declaring them so you can use property expressions.


Three years later and I needed to do this again. And struggled once more! So thought I’d summarize a few key points:

  • If the json data is an array that starts with the square braket ( ), then this won’t work. For example my REST API call is returning this structure in attribute jsonResult: m{“attrib1”: “value1”,...},{“attrib1”: “value1”,...},...{“attrib1”: “value1”,...}]. This is indeed an array but the .size property works on an object that has an array as a value. So if I use the query json
  • .size, I get no result but also no error.
  • This is easily fixable. Instead of pointing to the attribute jsonResult, I simply went to the text editor and supplied the following: {"mydata":@Value(jsonResult)}. I then used the query json “mydata”].size and got an integer result that reflected the number of objects/elements in the array.

Hope this helps someone, or myself in a few years when I forget again :D


Reply