tJavaRow replaceAll issue

One Star

tJavaRow replaceAll issue

Hello, I was trying to use tWriteJsonFiled to create a Nested Json and I am doing fine, except that the Json has an empty array where the value found to be null.
I have tried to use tJavaRow to replace those empty array with a null or empty space, but I am getting a nullPointer exception. Need help with this. I am using Talend Open Studio 6.2.1 version.
Example:
Output of tWriteJsonField:
"json": {
"id": "2",
"name": []
}
tJavaRow
output_row.name = input_row.name.replaceAll("\\", "");
If this is not the correct way to use, can someone please suggest good way to get rid of those empty Arrays.
Community Manager

Re: tJavaRow replaceAll issue

Hi 
It seems tWriteJsonField generates some null value, this leads to the nullpointer exception on tjavarow, for testing, add a tlogrow after tWritejsonfield to print the output values on the console, to check if there exist null values.
Regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: tJavaRow replaceAll issue

I have tried to put tlogRow after tWriteJsonField.
Here's what I wanted to do.
1. Connect to MySQL Database.
2. Get the records.
3. Transform the records by giving renaming them using tMap
4. Convert to Json for each row (Json should be nested). So I have used tWriteJsonField.
5. Send to REST API.
On step 4, I am not able to get the proper Json. It has the empty arrays, but no null values anywhere. That's the reason I thought of using the tJavaRow to replace the empty arrays with empty string.
If anyone has any better way for my series of steps, I really appreciate your help if you let me know.
Following is the response I have got by putting tLogRow after tWriteJsonField, but the tJavaRow gave a null pointer exception. Besides that, I am having some pipe symbols after each Json which is annoying.
I would also like to know if there is way to generate a nested Json without the name for the data block like "json" in the below response.
{
"json": {
"id": "1",
"template_id": [],
"time": "2015-09-22 11:37:47",
"person_id": [],
"person1": {
"person1_email": "jon.doe@gmail.com",
"person1_first_name": "Jon",
"person1_last_name": "Doe",
"person1_mobile_phone": []
},
"person2": {
"person2_first_name": "Foo",
"person2_last_name": "Bar",
"person2_rep": "foo.bar@gmail.com",
"person2_mobile_phone": []
}
}
} || || || || || || || || || || || || | {
"json": {
"id": "1",
"template_id": [],
"time": "2015-09-22 11:37:47",
"person_id": [],
"person1": {
"person1_email": "jon.doe@gmail.com",
"person1_first_name": "Jon",
"person1_last_name": "Doe",
"person1_mobile_phone": []
},
"person2": {
"person2_first_name": "Foo",
"person2_last_name": "Bar",
"person2_rep": "foo.bar@gmail.com",
"person2_mobile_phone": []
}
}
Community Manager

Re: tJavaRow replaceAll issue

Hi 
|| || || || || || || || || || || || |

What's this? It seems it generates duplicated records after tWriteJsonField. I confirm that the java code you used to replace empty array is right. 
I think the data block like 'json' is the root node, you can remove it by checking the 'Remove root note' box on tWriteJsonField.

Regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business