从 Talend 中的 JSON 文件中提取值

Extract values from JSON file in Talend

我有这样的 json 文件:

{"2020-04-28": { "37,N7L2H4,Carry,CHOPA,PLX": { "inter_results": { "inter_mark": "GITA" ,"down": null ,"up": null ,"wiki": {"included": "false", "options": ["RRR", "SSS","HHH"] }} ,"38, N5L2J4, HURT, SERRA, PZT": { "inter_results": { "inter_mark": "MARI" ,"down": "250" ,"up": "1250" ,"wiki": {"included": "true", "options": ["XXX", "YYY"] }} ,"39, N4L2H4, HIBA, FILA, PFG": { "inter_results": { "inter_mark": "HILO" ,"down": "100" ,"up": "250" ,"wiki": {"included": "true", "options": ["RTG", "VTH","HJI","JKL"] }} } }

我想使用 tFileInputJsonjsonPath.

从这个 json 文件中提取值 N7L2H4,N5L2J4,N4L2H4

使用 Talend 的原生组件,这很难实现。您可以使用一些 java 代码来完成,但它并不优雅。
这是一个使用来自 Talend Exchange 的 json 组件套件的解决方案,您可以下载 here

组件 tJSONDocTraverseFields 允许您列出 json 的所有字段、路径和值。 它给出了这个输出:

$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.inter_mark|4|inter_mark|"GITA"|false|21
$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.down|4|down|null|false|21
$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.up|4|up|null|false|21
$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.wiki.included|5|included|"false"|false|21
$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.wiki.options[0]|6|options|"RRR"|true|21
$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.wiki.options[1]|6|options|"SSS"|true|21
$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.wiki.options[2]|6|options|"HHH"|true|21
$.2020-04-28.38, N5L2J4, HURT, SERRA, PZT.inter_results.inter_mark|4|inter_mark|"MARI"|false|21
$.2020-04-28.38, N5L2J4, HURT, SERRA, PZT.inter_results.down|4|down|"250"|false|21
$.2020-04-28.38, N5L2J4, HURT, SERRA, PZT.inter_results.up|4|up|"1250"|false|21

然后您可以解析 json 路径以获取您想要的值:

我用“.”分割路径获取字段“37,N7L2H4,Carry,CHOPA,PLX”,然后在“,”上再次拆分结果并获取第一个值。
tJSONDocOpen 允许您初始化 json 文件,它充当连接。然后你 select 它在 tJSONDocTraverseFields.