Uh oh!
There was an error while loading. Please reload this page.
add new-lines & tabs to whitespace - #7
Conversation
MeirShpilraien
commented
Aug 25, 2022
I am not sure this is a valid json path, I guess tabs is OK, but new lines? @oshadmi what do you think? |
oshadmi
commented
Aug 25, 2022
Do you know the performance cost of being less strict and allowing white-spaces? I think that within a filter expression, or a function expression, it could be handy to allow white-spaces, even new-lines, and if we allow white-spaces in those, then the overall look of a path might not be easy/pretty to ready, so we should also allow indenting the entire JSONPath expression, e.g., $..book[?((@.category=="reference"||
@.price>12)&&
@.author=="J. R. R. Tolkien")]Anyway, it makes more sense to me to either allow all white-spaces everywhere, or not allow at all - much more intuitive and easier to explain. I tried the above JSONPath with Jayway JsonPath Evaluator and it works fine. But it seems even spaces are not supported by some underlying libraries (JSONPath may not be regarded as a full language, where you have a lexer that consumes white-spaces, as in more complex languages, but rather more like reg exp) We can also consider to not allow white-spaces and let the application/python client, other clients, etc., to actually strip the white-spaces if they prefer to be less strict. Tried this and even space/tab are either failing to return a valid result, or throw a Lexical error exception: const{JSONPath}=require('jsonpath-plus');constjsonpath=require('jsonpath');constjson={"a": 10,"b": [0,1,2,3,4,5]}constgood_paths=["$.a","$.b[1:3]","$"];constbad_paths=["$. a","$.b[ 1:3]"," $"];good_paths.forEach(test_jsonpath);bad_paths.forEach(test_jsonpath);functiontest_jsonpath(p){try{console.log("jsonpath-plus '"+p+"' = ")console.log(JSONPath({path: p,json: json}));}catch(e){console.log(e);}try{console.log("jsonpath '"+p+"' = ");console.log(jsonpath.query(json,p));}catch(e){console.log(e);}console.log("");} |
this PR allows newlines and tabs to be used everywhere space is allowed