Skip to content

How to get every single value from a special json #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
leonchen83 opened this issue Feb 24, 2022 · 4 comments
Closed

How to get every single value from a special json #68

leonchen83 opened this issue Feb 24, 2022 · 4 comments

Comments

@leonchen83
Copy link

leonchen83 commented Feb 24, 2022

I have a json like following

`json.set doc . '{"":"empty", "\\":"slash","\'":"quote","\n":"enter", "\"":"double quote", "\'\'":"quote quote", "\t":"tab", "/":"value"}'`

if I want to get value "empty". I can use json.get doc "['']"
but how can I get other key 's value?

@gkorland
Copy link
Contributor

Did you try ?

127.0.0.1:6379> json.get doc $.*
"[\"empty\",\"slash\",\"quote\",\"enter\",\"double quote\",\"quote quote\",\"tab\",\"value\"]"

@leonchen83
Copy link
Author

leonchen83 commented Feb 25, 2022

@gkorland
the purpose of doing this is we want to test some escape character of rejson.
so we want to get every single value of above json. and if test done, we could create a PR that convert RFC6901 style json path to rejson style json path. like PR67. and the above json could be a test case in that pr

@leonchen83 leonchen83 changed the title How to get every value from a specially json json.set doc . '{"":"empty", "\\":"slash","\'":"quote","\n":"enter", "\"":"double quote", "\'\'":"quote quote", "\t":"tab", "/":"value"}' How to get every single value from a specially json Feb 25, 2022
@leonchen83 leonchen83 changed the title How to get every single value from a specially json How to get every single value from a special json Feb 25, 2022
@gkorland
Copy link
Contributor

I assume you're getting an error like that:

127.0.0.1:6379> json.get doc '$.["\\"]'
(error) JSON Path error: path error: \n$.["\\"]\n^^^^^^^^\n

If you encountered issues it seems like the issue above the source is a redis-cli parsing issue.
If you'll try to run it with one of Redis clients e.g. redis-py it works without issues.

>>> r.json().get('doc', '$.["\n"]' )
['enter']
>>> r.json().get('doc', '$.["\t"]' )
['tab']
>>> r.json().get('doc', '$.["\"]' )
['empty']
>>> r.json().get('doc', '$.["\'"]' )
['quote']

@leonchen83
Copy link
Author

leonchen83 commented Feb 28, 2022

I try to use JRedisJson got the same error

String v = client.get("doc", String.class, Path.of(".[\"\\\\\"]"));
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: JSON Path error: path error: \n$.["\\"]\n^^^^^^^^\n
	at redis.clients.jedis.Protocol.processError(Protocol.java:139)
	at redis.clients.jedis.Protocol.process(Protocol.java:173)
	at redis.clients.jedis.Protocol.read(Protocol.java:227)
	at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:352)
	at redis.clients.jedis.Connection.getBinaryBulkReply(Connection.java:289)
	at redis.clients.jedis.Connection.getBulkReply(Connection.java:279)
	at com.redislabs.modules.rejson.JReJSON.get(JReJSON.java:246)
	at com.redislabs.modules.rejson.Main.main(Main.java:25)

and try String v = client.get("doc", String.class, Path.of(".[\"\\\"]"));

Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: JSON Path error: path error: \n$.["\"]\n^^^^^^^\n
	at redis.clients.jedis.Protocol.processError(Protocol.java:139)
	at redis.clients.jedis.Protocol.process(Protocol.java:173)
	at redis.clients.jedis.Protocol.read(Protocol.java:227)
	at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:352)
	at redis.clients.jedis.Connection.getBinaryBulkReply(Connection.java:289)
	at redis.clients.jedis.Connection.getBulkReply(Connection.java:279)
	at com.redislabs.modules.rejson.JReJSON.get(JReJSON.java:246)
	at com.redislabs.modules.rejson.Main.main(Main.java:25)

so I think it's not a redis-cli bug but a rejson module bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants