sripathikrishnan / redis-rdb-tools

Parse Redis dump.rdb files, Analyze Memory, and Export Data to JSON
https://rdbtools.com
MIT License
5.07k stars 739 forks source link

HASH with stringified JSON values getting escaped #105

Closed ttonyh closed 6 years ago

ttonyh commented 6 years ago

I'm successfully converting the dump.rdb file to a JSON document. My only problem is, is that nested JSON values (stringified) in a HASH are getting escaped.

Example:

[
    {
        "MYKEYPREFIX:KEY:123": { "timestamp":"1511469880891", "name": "abc", "data": "{\"prop1\":\"one\",\"prop2":\"two\"}" }
    }
]

This is the command I use:

rdb -c json -f my-output.json dump.rdb --type hash --key "MYKEYPREFIX.*" --escape raw

Is there a way that I could make it JSON-parse the items in a HASH that are JSON strings? That would save me from having to re-parse the document later on.

Thank you

oranagra commented 6 years ago

Hi, So i understand you're saving a JSON value inside a hash field, but from redis's perspective the hash contains strings, so when putting them into the JSON output they need to be quoted, and that also means escaping. there's currently no way to change that, and even if we wanted, i'm not sure how we can distinguish between fields that should be quoted (like "abc" above), and fields that should not be quoted.

ttonyh commented 6 years ago

Yes, you got it; thanks for your quick response. How about creating a custom parser for certain key/values in a HASH that will JSON parse the string? Can it be done and is there any code examples? Anyway to do it from the command line? I need the "options" included that I pasted above (key-regex, JSON, file output, raw etc.).

Thanks again,

oranagra commented 6 years ago

i understand you're now looking for a "private" solution, so you can either just modify your local code. or if you rather not, then you can probably derive some class or monkey patch it. sorry, i don't currently have the time to look for exact instructions.

ttonyh commented 6 years ago

Well, I was hoping I wasn't the only one that needed this, and if someone has solved this problem that they might have some sample code to post; something to point me in the right direction. Thanks for your help though, I appreciate it.