0

I'm currently using the Adobe Echosign API to format some data in a table. The output looks like this:

{
  "agreementId": "",
  "events": [
    {
      "actingUserEmail": "",
      "actingUserIpAddress": "",
      "date": "date",
      "description": "",
      "participantEmail": "",
      "type": "",
      "versionId": ""
    }
  ],
  "locale": "",
  "modifiable": false,
  "name": "",
  "nextParticipantSetInfos": [
    {
      "nextParticipantSetMemberInfos": [
        {
          "email": "",
          "waitingSince": "date"
        }
      ]
    }
  ],
  "participantSetInfos": [
    {
      "participantSetId": "",
      "participantSetMemberInfos": [
        {
          "email": "",
          "participantId": ""
        }
      ],
      "roles": [
        ""
      ],
      "status": ""
    }
  ],
  "status": "",
  "vaultingEnabled": false
}

I'm looping through multiple agreements and this outputs them each as a separate array.

This is probably a really basic question, but how would I go through each array and extract say the 'participantEmail', 'name' and 'status' values?

Thanks!

roo
  • 343
  • 1
  • 5
  • 17

2 Answers2

0

Depending on what programming language you are using, there are a lot of ways to handle this. In JS you could convert this JSON array into JS Array of Objects and after that you can access them using JS processing.

Example for JS would be:

var input = 'yourJSONstring';
var jsObject = JSON.parse(input);
for(var foo in jsObject){
 var name = foo.name;
    var participantEmail=  foo.events[0].participantEmail;
    var status = foo.participantEmail[0].status;
}
0

Supposing that you have an array of agreements with the format you provided, you could do something like this:

<?php

$json = '[{
  "agreementId": "",
  "events": [
    {
      "actingUserEmail": "",
      "actingUserIpAddress": "",
      "date": "date",
      "description": "",
      "participantEmail": "an email",
      "type": "",
      "versionId": ""
    }
  ],
  "locale": "",
  "modifiable": false,
  "name": "a name",
  "nextParticipantSetInfos": [
    {
      "nextParticipantSetMemberInfos": [
        {
          "email": "",
          "waitingSince": "date"
        }
      ]
    }
  ],
  "participantSetInfos": [
    {
      "participantSetId": "",
      "participantSetMemberInfos": [
        {
          "email": "",
          "participantId": ""
        }
      ],
      "roles": [
        ""
      ],
      "status": "a status"
    }
  ],
  "status": "",
  "vaultingEnabled": false
}]';

$parsed = json_decode($json, true);

$names = [];
foreach($parsed as $agreement) {

    $names[] = $agreement['name'];

    $emails = []; 
    foreach($agreement['events'] as $event) {
        $emails[] = $event['participantEmail'];
    }

    $status = []; 
    foreach($agreement['participantSetInfos'] as $participant) {
        $status[] = $participant['status'];
    }

}

var_dump($names);
var_dump($emails);
var_dump($status);

Of course you should do some checks for empty values and so, but just to give you an idea. Since you do not clarify the relation between name, status and email, i just took them in separate arrays, but that's nothing that can't be fixed with some array handling.

Hope this helps!