+ Start a Discussion
sheila srivatsavsheila srivatsav 

get json attribute value into aura:attribute

A lightning component makes an api call to an external service and the result is an json response

I have given the json response as follows.
 
{"readClaimResponse": {

   "status":    {

      "statusCode": "0",

      "detail": "SUCCESS"
   },

   "claim":    {

      "claimIdentifier":       {

         "idSource": "63",

         "idValue": "183245438591000",

         "idType": "pharmacyclaims"

      },

      "claimType": "Pharmacy",  

      "billedAmount": "520",

      "allowedAmount": "500.4",

      "planPaidAmount": "400.32",

      "totalMemberResponsibility": "100.08",

      "paidToProvider": "400.32",

      "deductible": "0.00",

      "claimProcessedDate": "2018-11-20T20:51:37.001100",

      "claimStatus": "Final",

      "dateOfServiceBegin": "2018-10-15",

      "dateOfServiceEnd": "2018-10-15",

      "providerName": "CVS PHARMACY 16890",

      "amountCoinsurance": "100.08",

      "amountCopay": "0.00",

      "healthClaimLines": [      {

         "amountCopay": "0.00",

         "amountCoinsurance": "100.08",

         "billedAmount": "520",

         "allowedAmount": "500.4",

         "deductible": "0.00",

         "paidAmount": "400.32",

         "memberResponsibility": "100.08",

         "procedureCode": [         {

            "procedureCode": "63323087715",

            "procedureCodeDescr": "Nebupent     Inh 300mg"

         }],

         "healthClaimLineIdentifier":          {

            "idSource": "100",

            "idValue": "FDGP2KT5800+001",

            "idType": "Healthclaimline"

         },

         "dateOfServiceBegin": "2018-10-15",

         "dateOfServiceEnd": "2018-10-15",

         "unitsOfService": "30.000"

      }]

   }

}}
what I am not understanding is how to get the "claimType" value into an aura:attribute for further processing.
I need the value of "claimType" i.e Pharmacy into an aura:attribute for further processing.
Please let me know how to achieve this at the very earliest.
Like I do not have much exp in json

thanks
sheila
Best Answer chosen by sheila srivatsav
Maharajan CMaharajan C
if you don't want use the for loop u can use like below:
        var strresponse = jsonresponse ;
        var claimdata = strresponse.readClaimResponse.claim;
        alert('$$$ = ' +claimdata.claimType );

All Answers

Raj VakatiRaj Vakati
You get as object type and get the key value with dot notation or convert it as an apex wrapper class and get the values 
 
<aura:attribute name="objectDescribe" type="object" required="false" description="results from apex describe call (JSON)"/>


sample code from the this link

https://github.com/mshanemc/soql2list/blob/master/src/aura/AllFieldDisplayer/AllFieldDisplayer.cmp
 
Maharajan CMaharajan C

Hi Sheila,

if you are storing the resonse in attribute the use the component.get('v.attrname'); in below 1st line.

        var strresponse = response data from 3rd party;
        var claimdata = strresponse.readClaimResponse.claim;
        for(var key in claimdata)
            {
                if(key == 'claimType')
                {
                    alert('@@@ claimType = ' + claimdata[key]);
                }
            }


=======================
For your confirmation you can run below code:


        var strresponse = {"readClaimResponse":{"status":{"statusCode":"0","detail":"SUCCESS"},"claim":{"claimIdentifier":{"idSource":"63","idValue":"183245438591000","idType":"pharmacyclaims"},"claimType":"Pharmacy","billedAmount":"520","allowedAmount":"500.4","planPaidAmount":"400.32","totalMemberResponsibility":"100.08","paidToProvider":"400.32","deductible":"0.00","claimProcessedDate":"2018-11-20T20:51:37.001100","claimStatus":"Final","dateOfServiceBegin":"2018-10-15","dateOfServiceEnd":"2018-10-15","providerName":"CVS PHARMACY 16890","amountCoinsurance":"100.08","amountCopay":"0.00","healthClaimLines":[{"amountCopay":"0.00","amountCoinsurance":"100.08","billedAmount":"520","allowedAmount":"500.4","deductible":"0.00","paidAmount":"400.32","memberResponsibility":"100.08","procedureCode":[{"procedureCode":"63323087715","procedureCodeDescr":"Nebupent     Inh 300mg"}],"healthClaimLineIdentifier":{"idSource":"100","idValue":"FDGP2KT5800+001","idType":"Healthclaimline"},"dateOfServiceBegin":"2018-10-15","dateOfServiceEnd":"2018-10-15","unitsOfService":"30.000"}]}}};
        var claimdata = strresponse.readClaimResponse.claim;
        for(var key in claimdata)
            {
                if(key == 'claimType')
                {
                    alert('@@@ claimType = ' + claimdata[key]);
                }
            }


   Can you please Let me know if it helps or not!!!

    If it helps don't forget to mark this as a best answer!!!


    Thanks,
    Maharajan.C
Maharajan CMaharajan C
if you don't want use the for loop u can use like below:
        var strresponse = jsonresponse ;
        var claimdata = strresponse.readClaimResponse.claim;
        alert('$$$ = ' +claimdata.claimType );
This was selected as the best answer
sheila srivatsavsheila srivatsav
Hello Maharajan
var strresponse = jsonresponse ;
        var claimdata = strresponse.readClaimResponse.claim;
        alert('$$$ = ' +claimdata.claimType );

The above worked perfectly for me.
thanks very much.