Skip to content

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

Closed

Description

@leonchen83

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?

Activity

  1. gkorland commented on Feb 24, 2022

    @gkorland
    Contributor

    Did you try ?

    127.0.0.1:6379> json.get doc $.*
    "[\"empty\",\"slash\",\"quote\",\"enter\",\"double quote\",\"quote quote\",\"tab\",\"value\"]"
    
  2. leonchen83 commented on Feb 25, 2022

    @leonchen83
    Author

    @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

  3. 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[/+] on Feb 25, 2022
  4. changed the title [-]How to get every single value from a specially json[/-] [+]How to get every single value from a special json[/+] on Feb 25, 2022
  5. gkorland commented on Feb 27, 2022

    @gkorland
    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']
  6. leonchen83 commented on Feb 28, 2022

    @leonchen83
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions