mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08:00
Removed redundant code, updated doc w.r.t reading json files
This commit is contained in:
@@ -1,5 +1,40 @@
|
||||
### Yaml2json
|
||||
### Yaml to Json
|
||||
To convert output to json, use the --tojson (or -j) flag. This can be used with any command.
|
||||
|
||||
### json2yaml
|
||||
To read in json, use the --fromjson (or -J) flag. This can be used with any command.
|
||||
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
|
||||
```
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
```
|
||||
yaml r <yaml file> <path>
|
||||
yaml r <yaml_file|json_file> <path>
|
||||
```
|
||||
|
||||
{!snippets/works_with_json.md!}
|
||||
|
||||
### Basic
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
|
||||
1
mkdocs/snippets/works_with_json.md
Normal file
1
mkdocs/snippets/works_with_json.md
Normal file
@@ -0,0 +1 @@
|
||||
This command can take a json file as input too, and will output yaml unless specified to export as json (-j)
|
||||
@@ -1,6 +1,7 @@
|
||||
```
|
||||
yaml w <yaml file> <path> <new value>
|
||||
yaml w <yaml_file|json_file> <path> <new value>
|
||||
```
|
||||
{!snippets/works_with_json.md!}
|
||||
|
||||
### To Stdout
|
||||
Given a sample.yaml file of:
|
||||
|
||||
Reference in New Issue
Block a user