0

I'm not able to model a nested JSON data in Google Data Studio. I have the problem exactly in the "addresses" field.

The JSON Data:


{
    "data": [
        {
            "id": 37314,
            "first_name": "Lio",
            "last_name": "Mino",
            "addresses": [
                {
                    "id": 7834,
                    "city": "Washington",
                    "primary": 1,
                },
                {
                    "id": 5034,
                    "city": "New yourk",
                    "primary": 1,
                }
             ]
         },
           ...
      ]
}

Without the addresses field all work fine. But i need to returned addresses also. I hope I explained the situation well.

bilalo
  • 129
  • 1
  • 1
  • 7

1 Answers1

0
function getAddresses() {
  const s = '{"data":[{"id":37314,"first_name":"Lio","last_name":"Mino","addresses":[{"id":7834,"city":"Washington","primary":1},{"id":5034,"city":"Newyourk","primary":1}]}]}';
  const obj = JSON.parse(s);
  const o=obj.data.map(e=>{return e.addresses.map(a=>{return a})});
  Logger.log(JSON.stringify(o))
}

Execution log
6:45:15 PM  Notice  Execution started
6:45:15 PM  Info    [[{"id":7834,"city":"Washington","primary":1},{"id":5034,"city":"Newyourk","primary":1}]]
6:45:15 PM  Notice  Execution completed
Cooper
  • 59,616
  • 6
  • 23
  • 54
  • I understand what you did, and thank you in advance. But i'm not able to see how that can help me in the getData() function.let me clarify more: the getData() response is like : `return { schema: requestedFields.build(), rows: rows };` The question is how to model the rows since i have nested JSON data? – bilalo Mar 30 '21 at 11:01
  • Yeah I don’t know what you’re talking about what do you mean by model what is it that you want to do – Cooper Mar 30 '21 at 15:17