I have a flat file which is similar to JSON(not exactly same). Final motive is to convert it into CSV (in specific order, not same as input JSON File ) and dump in database. now since the input file is not always in same order AWK, cut etc wont be useful. Need something like HASHMAP. Attaching sample Input and Expected out. Suggestions please.
Input JSON file sample (I have like 1000 files, 50K rows each, 200 columns each)
{"Field1":{"string":"Value,123"},"Field2":{"string":"564243"},"Field3":{"string":"SWCHP0001155"},"LOCATION":null,"OWNERUID":{"string":"655,,34"}}
{"Field1":{"string":"Value,456"},"Field2":{"string":"89565655"},"Field3":{"string":"SWCHP0001166"},"LOCATION":{"string":"BEACH,"},"OWNERUID":{"string":"65534"}}
........
Output CSV File Expected in specific order, lets say in order (OWNERUID, LOCATION, Field1, Field2, Field3)
655;;34,null,Value;123,564243,SWCHP0001155
65534,BEACH;,Value;456,89565655,SWCHP0001166
My idea so far is to do some string manipulation change eveything a standard format like below, transfer Data into hashmap, fetch in required and dump in CSV
Intermediate Standard format : (can be changed, please suggest)
Field1?Value;123,Field2?564243,Field3?SWCHP0001155,LOCATION?null,OWNERUID?655;;34
Field1?Value;456,Field2?89565655,Field3?SWCHP0001166,LOCATION?BEACH;,OWNERUID?65534
........
note:
- values contain , and other special characters
- I can change values a bit like converting commas to semicolon (like above)
- There are NULL values to be handled