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}]}"}]}]}'
Abhishek Chhabra
  • 120
  • 2
  • 14

1 Answers1

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}]}}'
oshadmi
  • 136
  • 3
  • 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... – Abhishek Chhabra Oct 10 '22 at 04:28
  • @AbhishekChhabra Can you please share the path you are trying to use? – oshadmi Oct 18 '22 at 05:50