0

I am trying to parse a nested JSON in CloudPage using GTL. I have reviewed the comments from other cases on this topic but unable to figure out the issue. Can someone review it and let me know if I am missing anything.

I am trying to retrieve the ChildSubcriptionID, FirstName, LastName from ChildInfo object.

    {
      "email": "[email protected]",
      "attributes": [
        {
          "name": "FirstName",
          "value": "testname"
        },
        {
          "name": "LastName",
          "value": "testlastname"
        },
        {
          "name": "UserName",
          "value": "testusername"
        },
        {
          "name": "childInfo",
          "value": [
            {
              "childSubscriptionId": 1000001,
              "FirstName": "Fred",
              "LastName": "Smith"
            },
            {
              "childSubscriptionId": 1000002,
              "FirstName": "Billy",
              "LastName": "Smith"
            },
            {
              "childSubscriptionId": 1000003,
              "FirstName": "Susan",
              "LastName": "Smith"
            }
          ]
        }
      ]
    }'
]%%

%%{={{ }}=}%%

{{.datasource JSONVar type=variable maxRows = 20}}
  {{.data}}
            { "target" : "@Json" }
  {{/data}}

   {{.datasource JSONAttribute type=nested maxRows = 10}}
              {{.data}}
                        { "target" : "JsonVar.attributes" }
              {{/data}}
                        {{JSONAttribute.name}}: {{JSONAttribute.value}}

                        {{.datasource JSONChildInfo type=nested maxRows = 10}}
                        {{.data}}
                          { "target" : "attributes.childInfo" }
                        {{/data}}
                             {{JSONChildInfo.name}}:  {{JSONChildInfo.value}}
                          {{/datasource}}  
    {{/datasource}}
{{/datasource}}

Output:
FirstName: testname
LastName: testlastname
UserName: testusername
childInfo: JSON Object Array

1 Answer 1

2

I was able to solve your issue as there were some key syntax errors and missing syntax. Also, pardon my noob GTL code as it has become bit rusty over time.

Moreover, for reference purpose, I have used below post from Eliot and Salesforce developer documentation:

Working code:

%%[ 
SET @json = '{
    "email": "[email protected]",
    "attributes": [
        {
            "name": "FirstName",
            "value": "testname"
        },
        {
            "name": "LastName",
            "value": "testlastname"
        },
        {
            "name": "UserName",
            "value": "testusername"
        },
        {
            "name": "childInfo",
            "value": [
                {
                    "childSubscriptionId": 1000001,
                    "FirstName": "Fred",
                    "LastName": "Smith"
                },
                {
                    "childSubscriptionId": 1000002,
                    "FirstName": "Billy",
                    "LastName": "Smith"
                },
                {
                    "childSubscriptionId": 1000003,
                    "FirstName": "Susan",
                    "LastName": "Smith"
                }
            ]
        }
    ]
}'
]%%

{{.datasource JSONVar type=variable maxRows = 20}}
{{.data}}
          { "target" : "@json" }
{{/data}}

        {{.datasource JSONAttribute type=nested maxRows = 10}}
        {{.data}}
            { "target" : "JsonVar.attributes" }
        {{/data}}

            {{.datasource JSONAttrValue type=nested maxRows = 20}}
                   {{.data}}
                        { "target" : "JSONAttribute.value" }
                   {{/data}}
                    <br>childSubscriptionId: {{JSONAttrValue.childSubscriptionId}}
                    <br>FirstName: {{JSONAttrValue.FirstName}}
                    <br>LastName: {{JSONAttrValue.LastName}}
                    <br>
    {{/datasource}}
  {{/datasource}}
{{/datasource}}

Output: enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .