简体   繁体   中英

Extract JSON fields without looping in Talend

On a json like the following

{ 
  'a' : 'hello'
  'b' : { 'c' : 'hello', 'd': 'hello2' }
}

I am unable to extract c and d because the component loops on b, if I specify json loop path to be "$.*" and field to be extracted 'b' .

What is the right way to configure the tExtractJsonFields for simple json extraction?

See my example below. I am using a tFileInputJSON component rather than tExtractJSONFields but they have the same properties available.

Diagram 1: json file. The only difference from yours is that I added a comma between the a and b fields, I am using double rather than single quotes, and I changed first value to hello_a. Otherwise it is the same as your example.

在此处输入图片说明

Diagram 2: input component. This is where the magic happens. You can see that I am using xPath rather than JSONPath (I have had better luck with it).

在此处输入图片说明

Diagram 3: this is the proof that all values were extracted.

在此处输入图片说明

You can also setup your json as metadata and experiment with it there. See diagram 4. This too shows that Talend can access all the data in the file, and will allow you to experiment with the file structure and path statements getting immediate results.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM