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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
lizzy1
Contributor III
Contributor III

Missing Fields to extract json

I am trying to ingest data from an API. Two of the fields are "DateStarted" and "DateCompleted". In the event that the task has been started but not completed, the "DateCompleted" key does not appear. In talend, I am using tExtractJSONFields to read this data, but whenever the "DateCompleted" key is missing, the whole row is skipped. How can I allow for missing keys within tExtractJSONFields? In the schema, I have the fields set as nullable, but it happens regardless.

The API also does report a true/false for "isCompleted" so I can check if the key would be there, if necessary, but I wanted to check if there was a simple way to fix this within tExtractJSONFields

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Here you go!

 

Its working even for tExtractJSONFields component.

0683p000009M7bJ.png

 

The component screenshots are as below.

0683p000009M7bO.png

 

0683p000009M7YG.png

 

I hope I have answered your query. If you are still facing issue, it might be due to problem in the JSON input message.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved

View solution in original post

11 Replies
Anonymous
Not applicable

Hi,

 

    Could you please share a sample input data file with 5 records and please also specify the expected output from this JSON data?

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved

 

 

lizzy1
Contributor III
Contributor III
Author

[

{DateStarted: 05/01/2016,

isCompleted: False},

{DateStarted: 01/23/2017,

DateCompleted: 06/20/2018

isCompleted: True},

{DateStarted: 07/21/2016,

isCompleted: False},

{DateStarted: 03/08/2018,

DateCompleted: 01/20/2019

isCompleted: True},

{DateStarted: 01/01/2017,

DateCompleted: 03/10/2017

isCompleted: True}

]

 

And I would expect the output to be like

Date Started | Date Completed

05/01/2016 | null

01/23/2017 | 06/20/2018

07/21/2016 | null

03/08/2018 | 01/20/2019

01/01/2017 | 03/10/2017

 

 

Anonymous
Not applicable

Hi,

 

    When I am trying to validate the JSON, its giving me error. Could you please do a quick validation in a JSON validator like JSONLint and share the correct JSON input data?

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved

lizzy1
Contributor III
Contributor III
Author

Here's the valid JSON

 

[{
"DateStarted": "05 / 01 / 2016",
"isCompleted": "False"
},
{
"DateStarted": "01 / 23 / 2017",
"DateCompleted": "06 / 20 / 2018",
"isCompleted": "True"
},
{
"DateStarted": "07 / 21 / 2016",
"isCompleted": "False"
},
{
"DateStarted": "03 / 08 / 2018",
"DateCompleted": "01 / 20 / 2019",
"isCompleted": "True"
},
{
"DateStarted": "01 / 01 / 2017",
"DateCompleted": "03 / 10 / 2017",
"isCompleted": "True"
}
]

Anonymous
Not applicable

Hi,

 

    Apologies for the delay as I was held up with some important tasks.

 

     Please refer the solution below. (Note:- Your input JSON is having space in date data. So the output is also reflecting the same way).

0683p000009M7af.png

The steps to do create the JSON input file in repository is as below. Right click to create new JSON file and fill the details as shown below.

0683p000009M7ap.png

 

0683p000009M7R5.png

0683p000009M7au.png

 

0683p000009M7az.png

 

0683p000009M7b4.png

 

Once the repository is created, drag the component to workspace and it will show two options as below. Select the first one and you are ready to read the data!

0683p000009M7Bn.png

 

I would appreciate if you could spare a second to mark the topic as resolved 🙂 Kudos will be a bonus!

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved

 

 

 

 

lizzy1
Contributor III
Contributor III
Author

As I explained in my initial post, my JSON is coming from an API, not a file. extractJSONFields does not seem to act in the same way as the component you are using. Are you suggesting that I should create a file of my raw JSON, save it, then read it?

Anonymous
Not applicable

Hi,

 

    Please try second option in that case and feed the input JSON data as input to tExtractJSONFields component.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved

lizzy1
Contributor III
Contributor III
Author

It fails whenever there is a field missing (dateCompleted), returning a blank row.

Anonymous
Not applicable

Here you go!

 

Its working even for tExtractJSONFields component.

0683p000009M7bJ.png

 

The component screenshots are as below.

0683p000009M7bO.png

 

0683p000009M7YG.png

 

I hope I have answered your query. If you are still facing issue, it might be due to problem in the JSON input message.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved