Can someone helps me finding out a solution for this problem with a command line?Here's my Json file :
{"type": "record","name": "ShelfEx »position,"fields": [ {"name": "shopId","type": {"type": "string","avro.java.string": "String" },"doc": "Id of the shop" }, {"name": "productId","type": {"type": "string","avro.java.string": "String" },"doc": "Id of the product" }, {"name": "sourceId","type": {"type": "string","avro.java.string": "String" },"doc": "Id of the source" }, {"name": "timestampTransmission","type": "long","doc": "Timestamp of the message" }, {"name": "productQuantity","type": ["null","double" ],"doc": "Quantity of the product","default": null } ]}and i want to get the name of each field, with it's type and eventually it's default value (null in the case of productQuantity).So the output should but something like :
"shopId" string"productId" string..."timestampTransmission" long"productQuantity" double nullAny idea please?
`cat file.json | jq -r '.fields[] | "\"\(.name)\" : \(.type | tostring | sub("^(null)$"; "\\1 : null") | sub("(^\"|\"$)"; ""))"'`Instead of :
"shopId" string"productId" string..."timestampTransmission" long"productQuantity" double nulli had :
"shopId" : {"type":"string","avro.java.string":"String"}"productId" : {"type":"string","avro.java.string":"String"}"sourceId" : {"type":"string","avro.java.string":"String"}"timestampTransmission" : long"productQuantity" : ["null","double"]