jsonpath function length() does not work

I want to determine the length of an json array with the length() function.
According to the knime documentation the jsonpath implementation is based on the Jayway library, whoch supports the length function.
I have the follwoing JSON array:

[
{“refId”:“1”,“groupRef”:“1-0”},
{“refId”:“2”,“groupRef”:“2-0”},
{“refId”:“3”,“groupRef”:“3-0”}
]

In a JSONPATH node I have applied the following JSONPATH Query:

$.length()

When testing the above example with the Jayway JsonPath Evaluator at https://jsonpath.herokuapp.com
I get the expected result 3.

When using the same JSON path query in Knime, I get a missing value result.
Can you either check if this is a bug or give any advice on how to get the length of json arrays?

Thanks for your efforts in advance!

1 Like

Hi @guidocarls,

thanks for asking and welcome to the forum :slight_smile:
Looking into the code with one of our devs, it seems that this currently isn’t possible. We expect a list/array, though the length function returns a single integer. I have opened a feature request (internal reference: AP-18152) to look into this in more detail.

A workaround for now is extracting a list and ungrouping it, to then read off the row count using the Extract Table Dimension node.

image

Kind regards
Marvin

5 Likes

You can also use the /Column Expressions to get the length of an array.

Cheers, Iris

4 Likes