How to set nested values (objects) using ReJSON

1.8k views Asked by At

If I insert the following object using ReJSON:

JSON.SET testing . '{"person":{"name":"John","surname":"Doe"}}'

Is there a way to "append" a nested structure? I would like to add "address.name" for an example to get the following JSON:

{
  "person": {
    "name": "John",
    "surname": "Doe"
  },
  "address": {
    "name": "Imaginary Street"
  }
}

I was trying to use JSON.SET testing .address.name '"Imaginary Street 7"' but this results in (error) ERR missing key at non-terminal path level.

The docs read:

A key (with its respective value) is added to a JSON Object (in a Redis ReJSON data type key) if and only if it is the last child in the path.

Is "address.name" not the last child in the path? What am I doing wrong?

1

There are 1 answers

0
Itamar Haber On BEST ANSWER

Since you're adding a dictionary ('address'), the way to go about this is:

JSON.SET testing .address '{"name": "Imaginary Street"}'

Alternatively, if you do just:

JSON.SET testing .address '{}'

you'll be able to use the command from your question without any errors.