2017-04-19 05:45:45 +00:00
|
|
|
### Yaml to Json
|
2017-04-13 05:36:59 +00:00
|
|
|
To convert output to json, use the --tojson (or -j) flag. This can be used with any command.
|
|
|
|
|
2017-04-19 05:45:45 +00:00
|
|
|
Given a sample.yaml file of:
|
|
|
|
```yaml
|
|
|
|
b:
|
|
|
|
c: 2
|
|
|
|
```
|
|
|
|
then
|
|
|
|
```bash
|
|
|
|
yaml r -j sample.yaml b.c
|
|
|
|
```
|
|
|
|
|
|
|
|
will output
|
|
|
|
```json
|
|
|
|
{"b":{"c":2}}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Json to Yaml
|
|
|
|
To read in json, just pass in a json file instead of yaml, it will just work :)
|
|
|
|
|
|
|
|
e.g given a json file
|
|
|
|
|
|
|
|
```json
|
|
|
|
{"a":"Easy! as one two three","b":{"c":2,"d":[3,4]}}
|
|
|
|
```
|
|
|
|
then
|
|
|
|
```bash
|
|
|
|
yaml r sample.json
|
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
a: Easy! as one two three
|
|
|
|
b:
|
|
|
|
c: 2
|
|
|
|
d:
|
|
|
|
- 3
|
|
|
|
- 4
|
|
|
|
```
|
|
|
|
|