Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Jennifer_siders
Contributor III
Contributor III

JSON Array Null check

Hi All,

JSON Payload:

{

  "customer-request": {

    "customer": {

    

      "ExternalId": "ab100",

      "CustomerType": "Individual",

      "FullName": "John Smith",

      "customerProducts": [

        {

          "ProductName": "Laptop",

          "Quantity": 1

        }

      ],

 "customerProducts": [

        {

          "ProductName": "Mouse",

          "Quantity": 1

        }

      ],

      "customerActivities": [

        {  

          "CustomerType": "Gold",

          "CustomerSource": "Web"

        }

      ]

    }

  }

}

 

Required OutPut:

 

0695b00000sOKpwAAG.png 

Talend Job is as follows:

0695b00000sOKo5AAG.png 

As you can see, if the JSON doesn't contain data for "customerActivities": []; then there is no data that is being passed from second tExtractJSONFields_2.

 

How can we write a code in tJavaRow component that can check for  "customerActivities": []; but still pass the rest of the fields to the output? or is there some other way ?

 

Thank you

Labels (2)
4 Replies
Jennifer_siders
Contributor III
Contributor III
Author

any help?

Anonymous
Not applicable

@Jennifer Siders​ ,It seems like it is an invalid Json sting for data extraction, there exists duplicate key 'customerProducts', you can't extract all data from duplicate key.

 

 

Jennifer_siders
Contributor III
Contributor III
Author

I don't think so...anyhow..we can assume it as CustomerType1, but the issue exists right?

Jennifer_siders
Contributor III
Contributor III
Author

My tJavaRow contains the following:

 

output_row.ExternalId = input_row.ExternalId;

output_row.CustomerType = input_row.CustomerType;

output_row.FullName = input_row.FullName;

output_row.CustomerActivities = input_row.CustomerActivities;

output_row.ProductName = input_row.ProductName;

output_row.Quantity = input_row.Quantity;

 

Now in some of the payloads the CustomerActivities[] can be empty and i need to hand this, so that next tExtractJSON can get the entire data.