Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have a sample json block as below --
{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
}
And my job as follows --
tFileInputJson-->tExtractJsonFields-->tMap-->tWriteJsonField-->tFileOutputDelimited
To extract "type" and "number" elements at tExtractJsonFields component, I am using Json query respectively as---
"$.phoneNumbers[*].type"
"$.phoneNumbers[*].number"
After my job finishes I need the output just like the input block. But instead I get as below --
{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers":
{
"type" : [ "iPhone","home"],
"number":[ "0123-4567-8888","0123-4567-8910"]
}}
What do I do to achieve separate type/number values in the output? What changes do I make changes and in which components?
Please reply. Thanks in advance.
Hi
If it is a json file, you can use tFileInputJson (without tExtractJsonField) to extract data from the file.On tWriteJsonField, you need to set phoneNumber as loop element and set group by columns, see:
This is the result on the console:
Starting job forum27908 at 15:49 14/06/2017.
[statistics] connecting to socket on port 3524
[statistics] connected
{"firstName":"John","lastName":"doe","age":"26","address":{"streetAddress":"naist street","city":"Nara","postalCode":"630-0192","phoneNumbers":[{"type":"iPhone","number":"31-10-9268"},{"type":"home","number":"31-10-9290"}]}}
[statistics] disconnected
Job forum27908 ended at 15:49 14/06/2017. [exit code=0]
Regards
Shong
I did exactly what you've said. I had put phoneNumbers as loop element and also had set group by columns (type & number). I still didn't get the required output. And I have to use tExtractJsonFields component because the input component may change in my job, also I need to perform some transformations on the columns using tMap. What do I do?
Hi
Which version of studio are you using? Can you export your job and upload it? It will be helpful for me to check what you are doing wrong in your job.
Regards
Shong
Hello
In this case, the phoneNumbers is an array element. You need to set Loop XPATH query to "/phoneNumbers", see