I have a JSON array of objects that I'm trying to convert to YAML.
{"AAPL": [
{
"shares": -75.088,
"date": "11/27/2015"
},
{
"shares": 75.088,
"date": "11/26/2015"
},
]}
Is there an equivalent representation in YAML that isn't just JSON? I'd like to do something like
AAPL:
- :
shares: -75.088
date: 11/27/2015
- :
shares: 75.088
date: 11/26/2015
but the cleanest thing I've come up with is
AAPL:
- {
shares: -75.088,
date: 11/27/2015
}
{
shares: 75.088,
date: 11/26/2015
}
Great answer above. Another way is to use the great yaml jq wrapper tool, yq at https://github.com/kislyuk/yq
Save your JSON example to a file, say ex.json and then
yq -y '.' ex.json
AAPL:
- shares: -75.088
date: 11/27/2015
- shares: 75.088
date: 11/26/2015
Source: Stackoverflow.com