0

I am trying to recreate this JSON but in my code the array leaves it out of the JSON object. I have not seen it in the documentation of how to keep it inside. This is my code in it's current state and how it exits. I've also added how I want it to look.

How I want it to look.

{
    "data": [
        {
          "external_id": "AlphaNumeric",
          "external_branch_id": "AlphaNumeric",
          "name": "Super Awesome Guy",
          "cellphone": "String_int",
          "gender": "(m/f only)",
          "autosuggest": int,
          "campaigns": [
               {
                    "name": "Super Awesome Campaign"
               }
          ]
        }
    ]
}

My code:

/* Create new JsonObjects */
oJson     = NEW JsonObject().
oJsonData = NEW JsonObject().

aJson1stTable = NEW JsonArray().
aJson2ndTable = NEW JsonArray().
//oJson:READ(TEMP-TABLE data:HANDLE).

oJson:Add("data", aJson1stTable).
aJson1stTable:READ(TEMP-TABLE data:HANDLE).
oJson:Add("campaigns", aJson2ndTable).
aJson2ndTable:READ(TEMP-TABLE campaigns:HANDLE).
//oJson:READ(TEMP-TABLE campaigns:HANDLE).

/* Write the JSON string to a character variable */ 
oJson:Write(jSon_string,TRUE). 

How are you getting it out:

{
  "data": [
    {
      "external_id": "97816",
      "external_branch_id": "1",
      "external_user_id": null,
      "name": "AIDE RODRIGUEZ MAR",
      "force_delete_rs": false,
      "rs": null,
      "cellphone": "1111111111",
      "telephone": "5555102609",
      "email": "[email protected]",
      "customer_category": null,
      "gender": "M",
      "birthday": "2001-11-09",
      "autosuggest": false,
      "force_delete_addresses": false
    }
  ],
  "campaigns": [
    {
      "name": "Bono Activo"
    }
  ]
}

If you can tell me how I should do it and where I was wrong.

1 Answer 1

3

You are adding the campaigns property to the top-level object

oJson:Add("campaigns", aJson2ndTable).

You need to add it to aJson1stTable instead

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.