猪的自定义JSON输出

时间:2016-02-16 14:21:17

标签: json apache-pig bigdata

需要定制的JSON输出 -

源文件 - abc.txt -

100002030,Tom,peter,eng,block 3, lane 5,california,10021

100003031,Tom,john,doc,block 2, lane 2,california,10021

100004032,Tom,jim,eng,block 1, lane 1,california,10021

100005033,Tom,trek,doc,block 2, lane 2,california,10021

100006034,Tom,peter,eng,block 6, lane 6,california,10021

我做了一些解析操作,下面是JSON输出

输出 -

{"rollno":"100002","firstname":"Tom","lastname:"peter","qualification":"eng","Address":"block 3 lane 5 california","zipcode":"10021"}

{"rollno":"100002","firstname":"Tom","lastname:"john","qualification":"doc","Address":"block 2 lane 2 california","zipcode":"10021"}

{"rollno":"100004","firstname":"Tom","lastname:"jim","qualification":"eng","Address":"block 1 lane 1 california","zipcode":"10021"}

{"rollno":"100005","firstname":"Tom","lastname:"trek","qualification":"doc","Address":"block 2 lane 2 california","zipcode":"10021"}

{"rollno":"100006","firstname":"Tom","lastname:"peter","qualification":"eng","Address":"block 6 lane 6 california","zipcode":"10021"}

现在,我需要将文件名和来源附加到每个字段

预期输出来源=社交

"file":"abc", "data": {"rollno.social":"100002","firstname.social":"Tom","lastname.social:"peter","qualification":"eng","Address.social":"block 3 lane 5 california","zipcode.social":"10021"}
"file":"abc", "data": {"rollno.social":"100002","firstname.social":"Tom","lastname.social:"john","qualification.social":"doc","Address.social":"block 2 lane 2 california","zipcode.social":"10021"}
"file":"abc", "data": 
{"rollno.social":"100004","firstname.social":"Tom","lastname.social:"jim","qualification.social":"eng","Address.social":"block 1 lane 1 california","zipcode.social":"10021"}

-------

请告知如何实现此目的,特别是在json字段输出

中为每个字段添加源名称