Groovy web console

subscribe to the feed Subscribe
to this
site
parse json arrays (via #groovywebconsole)
tweet this snippet Tweet
this
script

parse json arrays

Published 1 month ago by nmrao with tags parse json
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def json = '''[
      {
      "id": "58d17437e4b03ab8b267890",
      "accountId": "1234670",
      "subscriptionType": "Service",
      "amendments": [      {
         "accountId": "1234670",
         "productRatePlanChargeId": "2c92c0f84db91fc9014dcb82d20827ce",
         "productRatePlanId": "2c92c0f84db91f8b014dcb829bb83604",
         "subscriptionId": "2c92c0f95ae1445b015af2320235689f",
         "triggerEvent": "ServiceActivation",
         "quantity": 1,
         "deltaQuantity": 1,
         "accountBillCycleDay": 0,
         "chargeName": "Virtual Extension",
         "chargePrice": 14.99,
         "effectiveStartDate": 1491264000000,
         "version": 0,
         "createAmendment": true,
         "segment": 0,
         "upToPeriods": 1,
         "jurisdictionCode": "654300",
         "subsType": "Service",
         "priceChange": false,
         "flatFee": false,
         "lastSegment": false
      }],
      "requestType": "amendmentsProcessingRequest",
      "errorDetails": "class java.lang.RuntimeException: com.zuora.api.ZuoraServiceStub$ID.setID(ZuoraServiceStub.java)",
      "errorResolved": true,
      "errorResolveDateTime": 1490122048440,
      "retryCount": 1
   },
      {
      "id": "58d178b1e4b03ab8b2c6d8c3",
      "accountId": "1234670",
      "subscriptionType": "Service",
      "amendments": [      {
         "accountId": "1234670",
         "productRatePlanChargeId": "2c92c0f84db91fc9014dcb82d20827ce",
         "productRatePlanId": "2c92c0f84db91f8b014dcb829bb83604",
         "subscriptionId": "2c92c0f95ae1445b015af2320235689f",
         "triggerEvent": "ServiceActivation",
         "quantity": 1,
         "deltaQuantity": 1,
         "accountBillCycleDay": 0,
         "chargeName": "Virtual Extension",
         "chargePrice": 14.99,
         "effectiveStartDate": 1491264000000,
         "version": 0,
         "createAmendment": true,
         "segment": 0,
         "upToPeriods": 1,
         "jurisdictionCode": "654300",
         "subsType": "Service",
         "priceChange": false,
         "flatFee": false,
         "lastSegment": false
      }],
      "requestType": "amendmentsProcessingRequest",
      "errorDetails": "class java.lang.RuntimeException: com.zuora.api.ZuoraServiceStub$ID.setID(ZuoraServiceStub.java)",
      "retryData":       [
                  {
            "errorDetails": "class java.lang.RuntimeException: com.zuora.api.ZuoraServiceStub$ID.setID(ZuoraServiceStub.java)",
            "retryDate": 1490122934943
         },
                  {
            "errorDetails": "class java.lang.RuntimeException: com.zuora.api.ZuoraServiceStub$ID.setID(ZuoraServiceStub.java)",
            "retryDate": 1490125697891
         }
      ],
      "errorResolved": true,
      "errorResolveDateTime": 1490131063003,
      "retryCount": 3
   }     
 ]'''


def parsedJson = new groovy.json.JsonSlurper().parseText(json)
def ids = []
parsedJson.each { item ->
   item.amendments.each { amendment ->
      if (amendment.subscriptionId == '2c92c0f95ae1445b015af2320235689f') {
         ids << item.id
      }
   }
}

println ids