defiant.js
defiant.js copied to clipboard
Handle keys with numbers
Taking the following json, defiant.search(json, "//percents/15") returns Evaluation failed: DOMException: Failed to execute 'evaluate' on 'Document': The string '//percents//15' is not a valid XPath expression.
defiant.search(json, "//percents/*[@name='15']) returns {}
{
"volume": "1109718.9267420967",
"percents": {
"1": {
"buy_pressure": 154084.47,
"sell_pressure": 20663.32,
"books_24_hours_avg": 441286.47219814226
},
"2": {
"buy_pressure": 299911.21,
"sell_pressure": 299872.79,
"books_24_hours_avg": 836768.6396904029
},
"5": {
"buy_pressure": 403699.71,
"sell_pressure": 780519.51,
"books_24_hours_avg": 955530.720696594
},
"10": {
"buy_pressure": 403699.71,
"sell_pressure": 780519.51,
"books_24_hours_avg": 955747.7552476776
},
"15": {
"buy_pressure": 403699.71,
"sell_pressure": 780519.51,
"books_24_hours_avg": 955747.7552476776
}
},
"buy_pressure": "403699.71",
"markets_count": 1,
"sell_pressure": "780519.51",
"books_24_hours_avg": 955747.7552476776
},
Same issue :
defiant.search(search, '//2020-05-05[setStart]');
Failed to execute 'evaluate' on 'Document': The string '//2020-05-05[setStart]' is not a valid XPath expression.
{"search": { "2020-05-05": { "period": "weekly", "setStart": "2020-05-01" }, "2020-05-06": { "period": "daily", "setStart": "2020-05-01" } } }
Also tried without Hyphens :
Failed to execute 'evaluate' on 'Document': The string '//2020[setStart]' is not a valid XPath