Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

Exploring json with command lines

$
0
0

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 null

Any 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 null

i 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"]

Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>