JSONSelect
JSONSelect copied to clipboard
Unable to select numbers
Hi. The file shown below is a valid JSON object. However, unless I wrap numbers with the double quote, JSONSelect isn't able to select an object.
So, using this file:
{
"categories": [
{
"id": "1",
"name": "Test"
},
{
"id": 2,
"name": "Boom"
}
]
}
If I write
JSONSelect.match('.categories :has(.id:val("1"))', data);
it find the object. If I write
JSONSelect.match('.categories :has(.id:val("2"))', data);
it doesn't find the object (an empty array is returned).
I have just been looking at this library and was curious about this too. I figured out you can test numbers as follows:
JSONSelect.match('.categories :has(.id:expr(x=2))', data);
For both string or number, use the following:
JSONSelect.match('.categories :has(.id:expr(x=2 || x="2"))', data);