Nested mu.setSetJson only works to a depth of 1


(Cameron Batt) #1

Nested JSON only works for one level i.e:

This works

    const person = {
      name: "Alice",
      age: 26,
      loc: "Riley Street",
      married: true,
      schools: [
        {
          name: "Crown Public School",
        },
      ],
      friends: [
        {
          name: "Bob",
          age: 24,
        },
        {
          name: "Charlie",
          age: 29,
        },
      ],
    };

This does not

    const person = {
      name: "Alice",
      age: 26,
      loc: "Riley Street",
      married: true,
      schools: [
        {
          name: "Crown Public School",
        },
      ],
      friends: [
        {
          name: "Bob",
          age: 24,
          pets: [
             {name: 'bertie', type: 'dog}. // <<<<<<<<< pets will not persist 
           ]

        },
        {
          name: "Charlie",
          age: 29,
        },
      ],
    };

Is this by design?


(Michel Conrado) #2

I’ve tested your JSON, fixed some typos, but it’s working.

{
    "name": "Alice",
    "age": 26,
    "loc": "Riley Street",
    "married": true,
    "schools": [
      {
        "name": "Crown Public School"
      }
    ],
    "friends": [
      {
        "name": "Bob",
        "age": 24,
        "pets": [
           {"name": "bertie", "type": "dog"}
         ]
      },
      {
        "name": "Charlie",
        "age": 29
      }
    ]
  }
{
  q(func: has(married)){
    name
    age
    loc
    married
    schools {
        name
    }
    friends {
        name
        age
        pets {
          name
          type
        }
      }
  }
}

Result

{
  "data": {
    "q": [
      {
        "name": "Alice",
        "age": 26,
        "loc": "Riley Street",
        "married": true,
        "schools": [
          {
            "name": "Crown Public School"
          }
        ],
        "friends": [
          {
            "name": "Bob",
            "age": 24,
            "pets": [
              {
                "name": "bertie",
                "type": "dog"
              }
            ]
          },
          {
            "name": "Charlie",
            "age": 29
          }
        ]
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 28130,
      "processing_ns": 921444,
      "encoding_ns": 554486
    },
    "txn": {
      "start_ts": 54742
    }
  }
}

(Cameron Batt) #3

Thanks for the quick reply Michael, you are right it does work. I seem to have been using an older version of the DB for my initial test, maybe that was the issue.