Closed paulo-raca closed 1 year ago
If you want the string to always be bracket format you can start with the jp.B() function.
I'm not sure why you want to force bracket as strictly as you suggest. If there is an issue such as '''
that is a valid issue. I'll look at that tonight or tomorrow. The output should switch to bracket format on new line though. Non-ascii does not need to be escaped though. Many languages use non-ascii but valid unicode.
I'm not sure why you want to force bracket as strictly as you suggest
I don't really, but when the rules aren't clearly stated I am usually very conservative. I also misread the implementation and assumed it only checked for "." :man_facepalming:
Now that I'm looking at it again I can see I was wrong and it does check for line breaks and etc. Sorry! :man_facepalming:
There is, however, another issue: Child.tokenOK()
should disallow empty strings
jp.R().Child("").Child("a").String()
-> $..a
I also was wrong when I said it doesn't escape strings, everything else I've throw at it seems to be properly escaped.
'
was the first thing I tried and I apparently got lucky :sweat:
If you find any more let me know. I'll get the '''
escaped as it should.
Fixed in release v1.18.4 just now. It required one change to a character mapping table.
Thanks!
This is a follow-up to https://github.com/ohler55/ojg/issues/123 (Thansks a lot by the way :pray:)
I want to build a JsonPath string given a path in my datastructure.
E.g., if I want a path to
data["field1"][2]["😊"]
I should get$.field1[2]['😊']
As you suggested, I'm building it as
jp.R().Child("field1").N(2).Child("😊").String()
.However looks like Child.String() has a few issues:
It doesn't automatically switch to the
['fieldName']
syntax on when weird names are used (non-ascii, line breaks, etc), so in this example I get$.field1[2].😊
I suggesting changing
Child.tokenOk()
to match to something like this:^[a-zA-Z_][a-zA-Z_0-9]*$
(It is quite conservative on what it allows to use.fieldName
syntax)It doesn't perform string escaping (The complementary feature to #123!), so the output is sometimes invalid. E.g.,
R().Child(
').String()
is actually$[''']