2

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?

Guy Korland
  • 9,139
  • 14
  • 59
  • 106
alturkovic
  • 990
  • 8
  • 31

1 Answers1

4

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.

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117