Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSONata: method or function for testing JSON value datatype

Tags:

jsonata

JSONata offers conditional expressions and predicates which can be used to select values out of JSON trees.

However, I have not been able to find a way to test the datatype of a JSON value.

For example, given the array:

    [null, true, false, 1, 2.3, "a", ["x"], {}, {"y" : "z}]

I only want to pull out the numeric values.

    [1, 2.3]

Q: In a JSONata query, how does one test the JSON datatype (null, boolean, number, string, array, object) of a value?

like image 475
MTH Avatar asked Jul 09 '26 20:07

MTH


2 Answers

Currently there is no way to do this in JSONata. Worthy of an enhancement request though.

like image 147
Andrew Coleman Avatar answered Jul 21 '26 14:07

Andrew Coleman


Wow, today discovered this cool JSONata. Here is my try:

http://try.jsonata.org/

 [null, true, false, 1, 2.3, "a", ["x"], {}, {"y" : "z"}]
*[$ ~> /^[0-9\.]{1,}$/m]
like image 27
Victor Sembelidis Avatar answered Jul 21 '26 14:07

Victor Sembelidis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!