json path escaping with double quote

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

json path escaping with double quote

gwenn-6
Hello,
With the json1 extension, we can escape special characters like '['
from being interpreted as an array index by wrapping the path in
double quotes. But sometimes, it does not work:

sqlite> CREATE TABLE test (data TEXT);
sqlite> INSERT INTO test (data) VALUES ('{}');
sqlite> UPDATE test SET data = json_set(data, '$."equity_spot[at_andr]"', json(3
2));
sqlite> SELECT json_each.key, json_each.value FROM test, json_each(test.data);
"equity_spot[at_andr]"|32
sqlite> -- KO: expected equity_spot[at_andr]|32 but got
"equity_spot[at_andr]"|32
sqlite> DELETE FROM test;
sqlite> INSERT INTO test (data) VALUES ('{"equity_spot[at_andr]":34.3}');
sqlite> UPDATE test SET data = json_set(data, '$."equity_spot[at_andr]"', json(3
2));
sqlite> SELECT json_each.key, json_each.value FROM test, json_each(test.data);
equity_spot[at_andr]|32
sqlite> -- OK: no double quote

I use json_patch as a workaround.
Is this the expected behaviour ?
Thanks.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: json path escaping with double quote

gwenn-6
Ok,
I tried to patch this line:

diff --git a/ext/misc/json1.c b/ext/misc/json1.c
index d99d360b2..0bb4e1cee 100644
--- a/ext/misc/json1.c
+++ b/ext/misc/json1.c
@@ -1123,7 +1123,7 @@ static JsonNode *jsonLookupStep(
       u32 iStart, iLabel;
       JsonNode *pNode;
       iStart = jsonParseAddNode(pParse, JSON_OBJECT, 2, 0);
-      iLabel = jsonParseAddNode(pParse, JSON_STRING, i, zPath);
+      iLabel = jsonParseAddNode(pParse, JSON_STRING, nKey, zKey);
       zPath += i;
       pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr);
       if( pParse->oom ) return 0;

Regards.

On Thu, Jun 13, 2019 at 6:45 PM gwenn <[hidden email]> wrote:

>
> Hello,
> With the json1 extension, we can escape special characters like '['
> from being interpreted as an array index by wrapping the path in
> double quotes. But sometimes, it does not work:
>
> sqlite> CREATE TABLE test (data TEXT);
> sqlite> INSERT INTO test (data) VALUES ('{}');
> sqlite> UPDATE test SET data = json_set(data, '$."equity_spot[at_andr]"', json(3
> 2));
> sqlite> SELECT json_each.key, json_each.value FROM test, json_each(test.data);
> "equity_spot[at_andr]"|32
> sqlite> -- KO: expected equity_spot[at_andr]|32 but got
> "equity_spot[at_andr]"|32
> sqlite> DELETE FROM test;
> sqlite> INSERT INTO test (data) VALUES ('{"equity_spot[at_andr]":34.3}');
> sqlite> UPDATE test SET data = json_set(data, '$."equity_spot[at_andr]"', json(3
> 2));
> sqlite> SELECT json_each.key, json_each.value FROM test, json_each(test.data);
> equity_spot[at_andr]|32
> sqlite> -- OK: no double quote
>
> I use json_patch as a workaround.
> Is this the expected behaviour ?
> Thanks.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: json path escaping with double quote

gwenn-6
$ make quicktest
is ok with the patch.
I will try to provide some additional test cases.

On Sat, Jun 15, 2019 at 10:37 AM gwenn <[hidden email]> wrote:

>
> Ok,
> I tried to patch this line:
>
> diff --git a/ext/misc/json1.c b/ext/misc/json1.c
> index d99d360b2..0bb4e1cee 100644
> --- a/ext/misc/json1.c
> +++ b/ext/misc/json1.c
> @@ -1123,7 +1123,7 @@ static JsonNode *jsonLookupStep(
>        u32 iStart, iLabel;
>        JsonNode *pNode;
>        iStart = jsonParseAddNode(pParse, JSON_OBJECT, 2, 0);
> -      iLabel = jsonParseAddNode(pParse, JSON_STRING, i, zPath);
> +      iLabel = jsonParseAddNode(pParse, JSON_STRING, nKey, zKey);
>        zPath += i;
>        pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr);
>        if( pParse->oom ) return 0;
>
> Regards.
>
> On Thu, Jun 13, 2019 at 6:45 PM gwenn <[hidden email]> wrote:
> >
> > Hello,
> > With the json1 extension, we can escape special characters like '['
> > from being interpreted as an array index by wrapping the path in
> > double quotes. But sometimes, it does not work:
> >
> > sqlite> CREATE TABLE test (data TEXT);
> > sqlite> INSERT INTO test (data) VALUES ('{}');
> > sqlite> UPDATE test SET data = json_set(data, '$."equity_spot[at_andr]"', json(3
> > 2));
> > sqlite> SELECT json_each.key, json_each.value FROM test, json_each(test.data);
> > "equity_spot[at_andr]"|32
> > sqlite> -- KO: expected equity_spot[at_andr]|32 but got
> > "equity_spot[at_andr]"|32
> > sqlite> DELETE FROM test;
> > sqlite> INSERT INTO test (data) VALUES ('{"equity_spot[at_andr]":34.3}');
> > sqlite> UPDATE test SET data = json_set(data, '$."equity_spot[at_andr]"', json(3
> > 2));
> > sqlite> SELECT json_each.key, json_each.value FROM test, json_each(test.data);
> > equity_spot[at_andr]|32
> > sqlite> -- OK: no double quote
> >
> > I use json_patch as a workaround.
> > Is this the expected behaviour ?
> > Thanks.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: json path escaping with double quote

Dan Kennedy-4
In reply to this post by gwenn-6

On 13/6/62 23:45, gwenn wrote:
> Hello,
> With the json1 extension, we can escape special characters like '['
> from being interpreted as an array index by wrapping the path in
> double quotes. But sometimes, it does not work:

Thanks for reporting this. Now fixed here:

   https://sqlite.org/src/info/45bfcb88e71451a6

Dan.



>
> sqlite> CREATE TABLE test (data TEXT);
> sqlite> INSERT INTO test (data) VALUES ('{}');
> sqlite> UPDATE test SET data = json_set(data, '$."equity_spot[at_andr]"', json(3
> 2));
> sqlite> SELECT json_each.key, json_each.value FROM test, json_each(test.data);
> "equity_spot[at_andr]"|32
> sqlite> -- KO: expected equity_spot[at_andr]|32 but got
> "equity_spot[at_andr]"|32
> sqlite> DELETE FROM test;
> sqlite> INSERT INTO test (data) VALUES ('{"equity_spot[at_andr]":34.3}');
> sqlite> UPDATE test SET data = json_set(data, '$."equity_spot[at_andr]"', json(3
> 2));
> sqlite> SELECT json_each.key, json_each.value FROM test, json_each(test.data);
> equity_spot[at_andr]|32
> sqlite> -- OK: no double quote
>
> I use json_patch as a workaround.
> Is this the expected behaviour ?
> Thanks.
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users