0

i am using redis-cli for one of my project and i need to append the data into existing json in redis, i have tried json.arrappend but it is not working. i need to append in sDetail array and in jsonDetails array. any suggestions how to append in json in redis-cli

'{"xyz": [{"subType": 1,"sDetail": [{"eCs": "3","jsonDetails": "{\"ce\" :[{\"cRId\":272, \"cV\":10000, \"type\":1, \"tId\":0, \"uTid\":\"T00005\", \"sNumber\":\"53320\", \"sDetailId\":1101}]}"}]}]}'

1 Answer 1

1

jsonDetails is a string and not an array

127.0.0.1:6379> JSON.SET test $ '{"xyz": [{"subType": 1,"sDetail": [{"eCs": "3","jsonDetails": "{\"ce\" :[{\"cRId\":272, \"cV\":10000, \"type\":1, \"tId\":0, \"uTid\":\"T00005\", \"sNumber\":\"53320\", \"sDetailId\":1101}]}"}]}]}'
OK
127.0.0.1:6379> JSON.TYPE test $.xyz[0].sDetail[0].jsonDetails
1) "string"

If you set it like this

JSON.SET test $ '{"xyz": [{"subType": 1,"sDetail": [{"eCs": "3","jsonDetails": {"ce" :[{"cRId":272, "cV":10000, "type":1, "tId":0, "uTid":"T00005", "sNumber":"53320", "sDetailId":1101}]}}]}]}'

It would be an array

127.0.0.1:6379> JSON.TYPE test $.xyz[0].sDetail[0].jsonDetails.ce
1) "array"

And now you can append to it using JSON.ARRAPPEND, for example:

127.0.0.1:6379> JSON.ARRAPPEND test $.xyz[0].sDetail[0].jsonDetails.ce '{"new": "data"}'
1) (integer) 2

To append to sDetail you can try something like

JSON.ARRAPPEND test $.xyz[0].sDetail '{"eCs": "42", "jsonDetails": {"ce": [{"cRId":999, "cV": 888}]}}'
Sign up to request clarification or add additional context in comments.

2 Comments

127.0.0.1:6379> json.type test >> object ... this json type is object that's why i am getting error ERR Search path error at offset 1: an identifier can only begin with a letter, a dollar sign or an underscore - use bracket notation for anything else any suggestions on that...
@AbhishekChhabra Can you please share the path you are trying to use?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.