How to remove surrounding [] and double quotes when extracting JSON data?

Highlighted
Six Stars

How to remove surrounding [] and double quotes when extracting JSON data?

We have a file which contains JSON data.  Using tFileInputJson component to extract data from it and some of the fields are surrounded by [ ] and double quotes.  What is the best method to remove surrounding characters?

 

 

InputJson.PNG

 

Output:

RunWindow.PNG

 

InputFile:

{
"Options": [
{
"Value": 111111,
"Color": "#0000ff",
"IsManaged": false,
"ExternalValue": "",
"ParentValues": [],
"MetadataId": null,
"HasChanged": null,
"Label": {
"LocalizedLabels": [
{
"Label": "United States",
"LanguageCode": 1033
}
]
},
"Description": {
"LocalizedLabels": [
{
"Label": "TestDescription1"
}
]
}
},
{
"Value": 222222,
"Color": "#0000ff",
"IsManaged": false,
"ExternalValue": "",
"ParentValues": [],
"MetadataId": null,
"HasChanged": null,
"Label": {
"LocalizedLabels": [
{
"Label": "Canada",
"LanguageCode": 1033
}
]
},
"Description": {
"LocalizedLabels": [
{
"Label": "TestDescription2"
}
]
}
}
]
}

 

 

Tags (1)
Highlighted
Sixteen Stars
Sixteen Stars

Re: How to remove surrounding [] and double quotes when extracting JSON data?

It should be possible (?) within the tFileInputJSON but at least you can change the value using a tMap with this regex (not verified) for the desired fields:
row1.Label.replaceAll("[\[\]\"", "")

TRF
Highlighted
Community Manager

Re: How to remove surrounding [] and double quotes when extracting JSON data?

I think this might be because you have a wildcard in your JSONPath for the arrays. If you change the * to a 0 in [] for your values, this should remove the brackets. Of course, it will only return the first instance of the array.

2019 GARTNER 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

Put Massive Amounts of Data to Work

Learn how to make your data more available, reduce costs and cut your build time

Watch Now

How OTTO Utilizes Big Data to Deliver Personalized Experiences

Read about OTTO's experiences with Big Data and Personalized Experiences

Blog

Talend Integration with Databricks

Take a look at this video about Talend Integration with Databricks

Watch Now