0

I have json message and i have to retrieve two different values from it. I am used json path, but it does not retrieve any response. Following is the json message.

{
    "ContractAgreements": {
        "ContractAgreement": [
            {
                "Code": null,
                "ConnectionPoint": {
                    "Code": null,
                    "StartDate": null
                },
                "ContractedProducts": null
            },
            {
                "Code": 123,
                "ConnectionPoint": {
                    "Code": null,
                    "StartDate": null
                },
                "ContractedProducts": {
                    "ContractedProduct": {
                        "Code": "abc",
                        "ContractedOneOffCharges": {
                            "ContractedOneOffCharge": {
                                "ContractAgreementCode": 123,
                                "Charge": {
                                    "Code": "tekenbonus",
                                    "LanguageDescriptions": {
                                        "LanguageDescription": [
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": "teken bonus"
                                            },
                                            {
                                                "Description": "Signing Fee"
                                            }
                                        ]
                                    }
                                },
                                "OneOffChargeCode": "START",
                                "Status": "INACTIVE",
                                "Criteria1": null,
                                "Criteria2": null,
                                "Criteria3": null,
                                "AmountWithoutTax": null,
                                "OperationDate": null
                            }
                        },
                        "ContractedCharges": null,
                        "ContractedUsageCharges": null,
                        "TerminationReasonCode": null
                    }
                }
            },
            {
                "Code": 1234567,
                "LocationCode": 123,
                "Description": "test",
                "PackageCode": "abc",
                "StartDate": "2015-05-02T00:00:00Z",
                "Status": null,
                "EndDate": null,
                "CustomFields": null,
                "ConnectionPoint": {
                    "Code": null,
                    "StartDate": null
                },
                "ContractedProducts": {
                    "ContractedProduct": [
                        {
                            "Code": "DirectDebet",
                            "ContractAgreementCode": 123,
                            "Status": "TERMINATED",
                            "StartDate": "2015-05-02T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc Contract",
                            "ContractAgreementCode": 1234567,
                            "Status": "INACTIVE",
                            "StartDate": "2015-05-02T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        }
                    ]
                }
            },
            {
                "Code": "abc",
                "LocationCode": 123,
                "Description": "abc",
                "PackageCode": "abc",
                "StartDate": "2015-04-23T00:00:00Z",
                "Status": null,
                "EndDate": null,
                "CustomFields": null,
                "ConnectionPoint": {
                    "Code": 871687940005297500,
                    "StartDate": "2015-04-23T00:00:00Z"
                },
                "ContractedProducts": {
                    "ContractedProduct": [
                        {
                            "Code": "No",
                            "ContractAgreementCode": "abc",
                            "Status": "TERMINATED",
                            "StartDate": "2015-04-23T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc",
                            "ContractAgreementCode": "abc",
                            "Status": "TERMINATED",
                            "StartDate": "2015-04-23T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc",
                            "ContractAgreementCode": "abc",
                            "Status": "TERMINATED",
                            "StartDate": "2015-04-28T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": {
                                "ContractedUsageCharge": {
                                    "ContractAgreementCode": "abc",
                                    "Charge": {
                                        "Code": "Elektra High",
                                        "Description": "xyz",
                                        "InvoiceSubCategoryCode": "abc",
                                        "Disabled": false,
                                        "AmountEditable": true,
                                        "LanguageDescriptions": {
                                            "LanguageDescription": [
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": "Elektra Hoog"
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                }
                                            ]
                                        }
                                    },
                                    "Status": "TERMINATED",
                                    "Criteria1": null,
                                    "Criteria2": null,
                                    "Criteria3": null,
                                    "AmountWithoutTax": null,
                                    "CounterCode": "abc1"
                                }
                            },
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc",
                            "ContractAgreementCode": "abc",
                            "Status": "INACTIVE",
                            "StartDate": "2015-04-23T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": {
                                "ContractedRecurringCharge": {
                                    "ContractAgreementCode": "abc",
                                    "Charge": {
                                        "Code": "abc",
                                        "Description": "abc",
                                        "InvoiceSubCategoryCode": "abc",
                                        "Disabled": false,
                                        "AmountEditable": true,
                                        "LanguageDescriptions": {
                                            "LanguageDescription": [
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": "Elektra Capaciteits Tarief"
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": "xyz"
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                }
                                            ]
                                        }
                                    },
                                    "Status": "INACTIVE",
                                    "Criteria1": null,
                                    "Criteria2": null,
                                    "Criteria3": null,
                                    "StartDate": 1429747200000,
                                    "AmountWithoutTax": null,
                                    "OperationDate": "2015-04-23",
                                    "NextChargeDate": null
                                }
                            },
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        }
                    ]
                }
            }
        ]
    }
}

I have to retrieve "code":"Elektra High" from it and json path is given below.

ContractAgreements.ContractAgreement[2].Charge.Code

But it does not retrieve anything. Need Help.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
  • This might help: [Access / process nested objects, arrays or JSON](http://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) – Yogi May 10 '15 at 08:47

1 Answers1

0

try on php

<?php
$datas = '{
    "ContractAgreements": {
        "ContractAgreement": [
            {
                "Code": null,
                "ConnectionPoint": {
                    "Code": null,
                    "StartDate": null
                },
                "ContractedProducts": null
            },
            {
                "Code": 123,
                "ConnectionPoint": {
                    "Code": null,
                    "StartDate": null
                },
                "ContractedProducts": {
                    "ContractedProduct": {
                        "Code": "abc",
                        "ContractedOneOffCharges": {
                            "ContractedOneOffCharge": {
                                "ContractAgreementCode": 123,
                                "Charge": {
                                    "Code": "tekenbonus",
                                    "LanguageDescriptions": {
                                        "LanguageDescription": [
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": null
                                            },
                                            {
                                                "Description": "teken bonus"
                                            },
                                            {
                                                "Description": "Signing Fee"
                                            }
                                        ]
                                    }
                                },
                                "OneOffChargeCode": "START",
                                "Status": "INACTIVE",
                                "Criteria1": null,
                                "Criteria2": null,
                                "Criteria3": null,
                                "AmountWithoutTax": null,
                                "OperationDate": null
                            }
                        },
                        "ContractedCharges": null,
                        "ContractedUsageCharges": null,
                        "TerminationReasonCode": null
                    }
                }
            },
            {
                "Code": 1234567,
                "LocationCode": 123,
                "Description": "test",
                "PackageCode": "abc",
                "StartDate": "2015-05-02T00:00:00Z",
                "Status": null,
                "EndDate": null,
                "CustomFields": null,
                "ConnectionPoint": {
                    "Code": null,
                    "StartDate": null
                },
                "ContractedProducts": {
                    "ContractedProduct": [
                        {
                            "Code": "DirectDebet",
                            "ContractAgreementCode": 123,
                            "Status": "TERMINATED",
                            "StartDate": "2015-05-02T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc Contract",
                            "ContractAgreementCode": 1234567,
                            "Status": "INACTIVE",
                            "StartDate": "2015-05-02T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        }
                    ]
                }
            },
            {
                "Code": "abc",
                "LocationCode": 123,
                "Description": "abc",
                "PackageCode": "abc",
                "StartDate": "2015-04-23T00:00:00Z",
                "Status": null,
                "EndDate": null,
                "CustomFields": null,
                "ConnectionPoint": {
                    "Code": 871687940005297500,
                    "StartDate": "2015-04-23T00:00:00Z"
                },
                "ContractedProducts": {
                    "ContractedProduct": [
                        {
                            "Code": "No",
                            "ContractAgreementCode": "abc",
                            "Status": "TERMINATED",
                            "StartDate": "2015-04-23T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc",
                            "ContractAgreementCode": "abc",
                            "Status": "TERMINATED",
                            "StartDate": "2015-04-23T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc",
                            "ContractAgreementCode": "abc",
                            "Status": "TERMINATED",
                            "StartDate": "2015-04-28T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": null,
                            "ContractedUsageCharges": {
                                "ContractedUsageCharge": {
                                    "ContractAgreementCode": "abc",
                                    "Charge": {
                                        "Code": "Elektra High",
                                        "Description": "xyz",
                                        "InvoiceSubCategoryCode": "abc",
                                        "Disabled": false,
                                        "AmountEditable": true,
                                        "LanguageDescriptions": {
                                            "LanguageDescription": [
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": "Elektra Hoog"
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                }
                                            ]
                                        }
                                    },
                                    "Status": "TERMINATED",
                                    "Criteria1": null,
                                    "Criteria2": null,
                                    "Criteria3": null,
                                    "AmountWithoutTax": null,
                                    "CounterCode": "abc1"
                                }
                            },
                            "TerminationReasonCode": null
                        },
                        {
                            "Code": "abc",
                            "ContractAgreementCode": "abc",
                            "Status": "INACTIVE",
                            "StartDate": "2015-04-23T00:00:00Z",
                            "EndDate": null,
                            "Quantity": 1,
                            "ContractedOneOffCharges": null,
                            "ContractedRecurringCharges": {
                                "ContractedRecurringCharge": {
                                    "ContractAgreementCode": "abc",
                                    "Charge": {
                                        "Code": "abc",
                                        "Description": "abc",
                                        "InvoiceSubCategoryCode": "abc",
                                        "Disabled": false,
                                        "AmountEditable": true,
                                        "LanguageDescriptions": {
                                            "LanguageDescription": [
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": "Elektra Capaciteits Tarief"
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": "xyz"
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                },
                                                {
                                                    "Code": "abc",
                                                    "Description": null
                                                }
                                            ]
                                        }
                                    },
                                    "Status": "INACTIVE",
                                    "Criteria1": null,
                                    "Criteria2": null,
                                    "Criteria3": null,
                                    "StartDate": 1429747200000,
                                    "AmountWithoutTax": null,
                                    "OperationDate": "2015-04-23",
                                    "NextChargeDate": null
                                }
                            },
                            "ContractedUsageCharges": null,
                            "TerminationReasonCode": null
                        }
                    ]
                }
            }
        ]
    }
}';
$datas = json_decode($datas);
echo '<pre>';
print_r($datas->ContractAgreements->ContractAgreement[3]->ContractedProducts->ContractedProduct[2]->ContractedUsageCharges->ContractedUsageCharge->Charge->Code);

should be this on js

data.ContractAgreements.ContractAgreement[3].ContractedProducts.ContractedProduct[2].ContractedUsageCharges.ContractedUsageCharge.Charge.Code

the result of that is "Elektra High"

Josua Marcel C
  • 3,122
  • 6
  • 45
  • 87