Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I'm new to Talend and I have this issue. I have a XML like this:
<product>
<productCode>Code1</productCode>
<productName>Name1</productName>
<Users>
<productUser>User1</productUser>
<productUser>User2</productUser>
</Users>
</product>
And i have to convert this to a JSON. Does anyone know how to achieve this?
expected JSON-array:
[{"productCode":"Code1","productName":"Name1","Users":["User1","User2"]}]
This method may work for you.....I haven't tested it since 2018 though. So it would be interesting to see how it works for you 😉
https://community.talend.com/s/question/0D53p00007vCjPdCAK/a-simple-way-to-convert-an-xml-string-to-json
Unfortunately your link to the jar doesn't work anymore...
I believe this one may work. It might need a slight refactoring of the code, but I suspect it probably won't.
https://jar-download.com/artifacts/org.json
FYI if you are looking for a Jar, look at the imports and Google an import package with "jar" at the end (in this case I Googled "org.json.jsonobject jar").
Thanks it worked.
But now I need to extract the values of the productUsers.
I tried it with a tExtractXmlField with a loop on Users, but the result is only the first value (user1).
Is it unpossible because the tagnames are exactly the same and the number of users are different each product? any ideas?
Are you using the tExtractXMLField with the JSON you have just created? If so, that won't work. You need to show more detail here. Maybe a screenshot of how you have set up your tExtractXMLField.
No with the same XML as posted in my original question
Do you have any screenshots of your configuration of the tExtractXMLField?
I tried this, but this gives me one User instead of the expected two.
Your loop needs to be.....
"/product/Users/productUser"
You will then need to tweak your other values as they will be at the level above.