java - Join two jsons based on element -
i have 2 json files. need parse , join json single structure
lineage.json
{ "lineage": [{ "sourcecolumnid": "vmb_bestaddress.snapshot_ts", "description": "", "targetcolumnid": "vmb_bestaddressusage.nxreins" }, { "sourcecolumnid": "dsl_record_sources.mamact", "description": "", "targetcolumnid": "g2_zumadf00.mamact" }, { "sourcecolumnid": "dsl_record_sources.mamade", "description": "", "targetcolumnid": "g2_zumadf00.hdf_s_pol_gen" }] }
column.json
{ "column": [{ "id": 39700, "columnid": "vmb_bestaddress.snapshot_ts", "column": "snapshot_ts", "datatype": "string", "length": "", "table": "vmb_bestaddress", }, { "id": 39701, "columnid": "vmb_bestaddressusage.nxreins", "column": "nxreins", "datatype": "string", "length": "", "table": "vmb_bestaddressusage", }, { "id": 39702, "columnid": "vmb_bestaddressusage.pkaddresscode", "column": "pkaddresscode", "datatype": "string", "length": "", "table": "vmb_bestaddressusage", }] }
i need join 2 jsons such every match of sourcecolumnid , targetcolumnid in column following json structure must populated
{ output:{ sourcecolumnid:vmb_bestaddress.snapshot_ts, sourcecolumnname:snapshot_ts, targetcolumnid:vmb_bestaddressusage.nxreins, targetcolumnnamenxreins, } }
i need join lookup 2 json output such
sourcecolumnname -> column name column.json columnid , sourcecolumnid same. targetcolumnname also.
string str = "xxx"; // column.json jsonarray jsonarraycolumn = json.parseobject(str); map<string, jsonobject> column = new hashmap(); // {id:name} for(int = 0; < jsonarraycolumn.size(); i++){ // loop jsonobject obj = jsonarraycolumn.getjsonobject(i); column.put(obj.getstring("columnid"), obj.getstring("column")); } string str2 = "xxx"; // lineage.json jsonarray jsonarraylineage = json.parseobject(str2); jsonarray resultarray = new jsonarray(); for(int = 0; < jsonarraylineage.size(); i++){ // loop jsonobject lineageobj = jsonarraylineage.getjsonobject(i); jsonobject obj = new jsonobject(); obj.put("sourcecolumnid", lineageobj.get("sourcecolumnid")); obj.put("sourcecolumnname", column.get(lineageobj.get("sourcecolumnid"))); obj.put("targetcolumnid", lineageobj.get("targetcolumnid")); obj.put("targetcolumnname", column.get(lineageobj.get("targetcolumnid"))); }
the resultarray
want.
Comments
Post a Comment