Expression length of JSON object/array

Does anyone know if its possible to get the length of a JSON array or JSON object via the expression language in Perspective? Unfortunately, both len({property}) and {property.length} don’t work. I can at least test for empty-ness via: Expression to test for empty json query result. But if possible I would like to get a size back so I don’t have to use a script (and thus add to gateway load).

Unfortunate that the Expression language’s len() doesn’t work. I took the liberty of creating an idea post here to throw the ball into IA’s court just in case it hasn’t come up yet.

A script is an easy way to work around this–Python’s len() function will work as expected. If you’re skittish about performance of an expression vs. a script on your gateway load, consider that evaluating expressions would have to be performed somewhere, too (i.e., the gateway). No free lunch computation, after all.

3 Likes

Yeah, having len, sum, etc work with JSON objects is something on our radar, just hasn’t come back to the top of the pile yet.

1 Like

I guess I didn’t think through expressions also being evaluated on the gateway. That’s pretty obvious after a few seconds of thought.

It would be super cool if those could be interpreted by the browser on the client side.

Well, aside from the technical hurdles of implementing the actual code expressions use in Javascript, it wouldn’t actually be any performance benefit - component properties and the like are already synchronized between the frontend and backend.

1 Like