Get size/length of elements() // JavaScript Task - Modeler

Is it possible to get the length of a json/spin list ?

json.prop("array").elements()

or a simple solution to check if the array is empty or contains elements?

Another question: I work with the REST API to get some input (JSON-String) - values to can work in the Camunda Modeler. To use them i have to convert the values by using Camunda Spin S(json).
To navigate through the json tree, always i have to do this “prop” notation …
is there some easier way to get the normal syntax of a json in JavaScript?

do stuff like this: json.array[0].name ... json.array.length ... json.object.subObject.list

You can convert your spin object into JS Json with JSON.parse(myVar.prop("mykey").elements().toString())

This will return a regular js array that you can work with with Js notations

Does that mean there’s no Spin API to get the array length?

Since Camunda Spin API strangely needs to use JavaScript’s JSON.parse to get array length, I found a good enough workaround that doesn’t require JavaScript:

chartMogulResponse.jsonPath('$.entries.length()').numberValue() 

Not a “proper” I guess, but at least this way there’s no need to convert it to String then parse it to JavaScript object to get the array length.

I just needed this too and this method works for me.