Solved

JSON Query - "size" & "type" not working

  • 8 February 2021
  • 6 replies
  • 13 views

Badge +3

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 json[0].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 'json["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.

icon

Best answer by ebygomm 8 February 2021, 18:55

View original

6 replies

Userlevel 1
Badge +21

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"]["metadata"]["country_of_origin"].size

 

 

Badge +3

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"]["metadata"]["country_of_origin"].size

 

 

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

Userlevel 1
Badge +21

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

Badge +3

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.

Userlevel 1
Badge +21

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.

Badge +3

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.

Reply