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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

What is the best way to modify fields in a complex JSON document?

Hello,

 

I'm trying to come up with a way to be able to make modifications to a "complex" JSON document using Talend.  However, I can't seem to get any one method working at all.  First, below is a sample JSON document to illustrate the structure:

 

{
    "title": "foo",
    "team":
    [
        {
            "name": "Team 1",
            "collaborators":
            [
                {
                    "name": "Team 3"
                }
            ]
        },
        {
            "name": "Team 2",
            "collaborators":
            [
                {
                    "name": "Team 3"
                }
            ]
        }
    ]
}

FYI, we're using Talend Open Studio for Data Integration 7.0.

 

To start, I wanted to find a way to modify the $.team.collaborators.name, such as converting the text to uppercase.  The main requirement of this flow is that the document needs to be written out in a similar structure as it came in as it's going to end up in a document store.  E.g. I can't break it out into rows.  So, regardless of any changes I make, it has to result in a single document.  The overall structure won't change much, except we may remove some unneeded fields.

 

I first tried to do this with the built-in JSON processors and came to the conclusion that they wouldn't work because everything I found made it look like the data would have to be flattened into a schema.  Next, I downloaded and installed the tJsonDoc processors and didn't have much more luck.  I could successfully open the document, but I couldn't extract a using tJsonDocExtraction, which may be deprecated as I don't see it on their Github page anymore.  Lastly, I tried to use tJavaRow and tJavaFlex to use Jackson directly to create the processor I require, but the closest I got was starting to use tJavaFlex and getting an error that it couldn't find ObjectMapper.  The funny thing here is that I was following what is in another post that supposedly worked.  I diverted slightly into creating a routine, but I couldn't import jackson even though I can see under the Modules view that it is installed.

 

So, what is the cleanest/best way to do this?

Labels (4)
2 Replies
David_Beaty
Specialist
Specialist

Hi,

 

I would suggest you tLibraryLoad "org.json.jar" and make the changes you need manually in something like a tJavaRow

 

Anonymous
Not applicable
Author

Hello,

 

So, are you saying that there's no way to leverage the built-in Jackson library that comes with Talend?  It seems silly that one comes with the product, but we can't use it in a tJava_ component.