getting arrays from the nulls in strings and nulls in integer values tWriteJSONField

Nine Stars

getting arrays from the nulls in strings and nulls in integer values tWriteJSONField

Hello All

 

Am writing to JSON file from CSV, in that process see the below json file how it is generated 

 

"object": {
"number": "1548364482",  
"ID": "378827052",
"name": [],  (string datatype)
"ChainNumber": [],  (integer datatype)

"dispenserTypeCode": "1"

 

 

For the above string and integer data types i don't have any data  in my CSV which are null

 

So my expected output is below

 

"object": {
"number": "1548364482",
"ID": "378827052",
"name": "",  (string datatype)
"ChainNumber": null, ( for integer datatype)

"dispenserTypeCode": "1"

 

 

Can any one help me how to configure the twritejsonfeilds to get this kind of output

 

Thanks In Advance

Manish

Employee

Re: getting arrays from the nulls in strings and nulls in integer values tWriteJSONField

Hi Manish,

 

    What about your input data? Is it an array for these problematic columns? Could you please share 5 input sample records so that we will get more idea?

 

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

Nine Stars

Re: getting arrays from the nulls in strings and nulls in integer values tWriteJSONField

@nikhilthampi Thanks

 

My input data is below, if we don't have a data while getting from csv and writing to json am not getting empty strings, rather getting empty arrays for string and integer like this [], [] , []

 

Booleanstringstringint
FALSENoGeneric1
FALSENonGeneric2
    
FALSENoneGeneric4

 

 

Thanks

Manish

Highlighted
Employee

Re: getting arrays from the nulls in strings and nulls in integer values tWriteJSONField

Hi Manish,

 

    Your input and output data looks totally different in your previous posts. Lets start again on a clean slate. Could you please provide 5 input records and corresponding JSON output in expected and actual cases?

 

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

Nine Stars

Re: getting arrays from the nulls in strings and nulls in integer values tWriteJSONField

Thanks @nikhilthampi 

 

The above below is the input csv

 

Booleanstringstringint
FALSENoGeneric1
FALSENonGeneric2
    
FALSENoneGeneric4

 

 

And the Json am getting is like below

 

"json": [

{

"Boolean" :false,

"string" :"no",

"string": "generic",

"int":1

},

{

"Boolean" :false,

"string" :"non",

"string": "generic",

"int":2

},

{

"Boolean" :[],

"string" : [],

"string": [],

"int":[]

},

{

"Boolean" :false,

"string" :"none",

"string": "generic",

"int":4

}

 

 

 

Please look at the red highlighted one, how would i rectify that

 

 

that highlighted red is expected in this format

 

{

"Boolean" :  ,

"string" :"",

"string": "",

"int":null

}

 

 

Thanks

Manish

Employee

Re: getting arrays from the nulls in strings and nulls in integer values tWriteJSONField

Hi Manish,

 

      There seems to be some problem in the input JSON you have provided. I would recommend to test it with JSONLint or some other tool. 

 

      Coming to the issue, you are trying to load a Boolean and integer value with empty string. The concept about boolean is that if true value is not available, by default, it will become false. So you will have to either provide true or false value. The best chance in your case will be to convert all the columns to String and then do the JSON conversion.

 

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

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog