JRedisJSON icon indicating copy to clipboard operation
JRedisJSON copied to clipboard

How to get every single value from a special json

Open leonchen83 opened this issue 3 years ago • 4 comments

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?

leonchen83 avatar Feb 24 '22 10:02 leonchen83

Did you try ?

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

gkorland avatar Feb 24 '22 13:02 gkorland

@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 avatar Feb 25 '22 01:02 leonchen83

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']

gkorland avatar Feb 27 '22 08:02 gkorland

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.

leonchen83 avatar Feb 28 '22 02:02 leonchen83