I have json mapping under properties
key as below in a file Customer.json,
{ "customer": { "properties": { "customerId": { "type": "string", "index": "not_analyzed" }, "name": { "type": "string", "index": "not_analyzed" } } } }
Which I want to convert into following with key
and displayName
duplicated and type
from above mapping,
field(key: 'customerId', displayName: 'customerId', type: 'String') field(key: 'name', displayName: 'name', type: 'String')
I hit and tried bash + python as below assuming it fetched customer key first and loops inside properties ,
$ cat Customer.json | python -c 'import sys; import simplejson as json; \ print "\n".join( [i["properties"] for i in json.loads( sys.stdin.read() )["customer"]] )' Traceback (most recent call last): File "<string>", line 2, in <module> TypeError: string indices must be integers, not str
I'm open to other solutions as well.