1
0
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:
Mike Farah
2017-04-19 15:45:45 +10:00
parent c2000a446b
commit ec25886528
16 changed files with 114 additions and 113 deletions

View File

@@ -252,15 +252,15 @@
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#yaml2json" title="Yaml2json" class="md-nav__link">
Yaml2json
<a href="#yaml-to-json" title="Yaml to Json" class="md-nav__link">
Yaml to Json
</a>
</li>
<li class="md-nav__item">
<a href="#json2yaml" title="json2yaml" class="md-nav__link">
json2yaml
<a href="#json-to-yaml" title="Json to Yaml" class="md-nav__link">
Json to Yaml
</a>
</li>
@@ -293,15 +293,15 @@
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#yaml2json" title="Yaml2json" class="md-nav__link">
Yaml2json
<a href="#yaml-to-json" title="Yaml to Json" class="md-nav__link">
Yaml to Json
</a>
</li>
<li class="md-nav__item">
<a href="#json2yaml" title="json2yaml" class="md-nav__link">
json2yaml
<a href="#json-to-yaml" title="Json to Yaml" class="md-nav__link">
Json to Yaml
</a>
</li>
@@ -323,10 +323,39 @@
<h1>Convert</h1>
<h3 id="yaml2json">Yaml2json</h3>
<h3 id="yaml-to-json">Yaml to Json</h3>
<p>To convert output to json, use the --tojson (or -j) flag. This can be used with any command.</p>
<h3 id="json2yaml">json2yaml</h3>
<p>To read in json, use the --fromjson (or -J) flag. This can be used with any command.</p>
<p>Given a sample.yaml file of:</p>
<pre><code class="yaml">b:
c: 2
</code></pre>
<p>then</p>
<pre><code class="bash">yaml r -j sample.yaml b.c
</code></pre>
<p>will output</p>
<pre><code class="json">{&quot;b&quot;:{&quot;c&quot;:2}}
</code></pre>
<h3 id="json-to-yaml">Json to Yaml</h3>
<p>To read in json, just pass in a json file instead of yaml, it will just work :)</p>
<p>e.g given a json file</p>
<pre><code class="json">{&quot;a&quot;:&quot;Easy! as one two three&quot;,&quot;b&quot;:{&quot;c&quot;:2,&quot;d&quot;:[3,4]}}
</code></pre>
<p>then</p>
<pre><code class="bash">yaml r sample.json
</code></pre>
<p>will output</p>
<pre><code class="yaml">a: Easy! as one two three
b:
c: 2
d:
- 3
- 4
</code></pre>

View File

@@ -328,7 +328,7 @@
<h1 id="yaml">yaml</h1>
<p>yaml is a lightweight and flexible command-line YAML processor</p>
<p>yaml is a lightweight and portable command-line YAML processor</p>
<p>The aim of the project is to be the <a href="https://github.com/stedolan/jq">jq</a> or sed of yaml files.</p>
<h3 id="download-latest-binary"><a href="https://github.com/mikefarah/yaml/releases/latest">download latest binary</a></h3>
<h3 id="get-the-source">get the source</h3>

View File

@@ -2,12 +2,12 @@
"docs": [
{
"location": "/",
"text": "yaml\n\n\nyaml is a lightweight and flexible command-line YAML processor\n\n\nThe aim of the project is to be the \njq\n or sed of yaml files.\n\n\ndownload latest binary\n\n\nget the source\n\n\ngo get github.com/mikefarah/yaml\n\n\n\n\n.zip\n or \ntar.gz\n\n\nView on GitHub",
"text": "yaml\n\n\nyaml is a lightweight and portable command-line YAML processor\n\n\nThe aim of the project is to be the \njq\n or sed of yaml files.\n\n\ndownload latest binary\n\n\nget the source\n\n\ngo get github.com/mikefarah/yaml\n\n\n\n\n.zip\n or \ntar.gz\n\n\nView on GitHub",
"title": "Install"
},
{
"location": "/#yaml",
"text": "yaml is a lightweight and flexible command-line YAML processor The aim of the project is to be the jq or sed of yaml files.",
"text": "yaml is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files.",
"title": "yaml"
},
{
@@ -22,7 +22,7 @@
},
{
"location": "/read/",
"text": "yaml r \nyaml file\n \npath\n\n\n\n\n\nBasic\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyaml r sample.yaml b.c\n\n\n\n\nwill output the value of '2'.\n\n\nFrom Stdin\n\n\nGiven a sample.yaml file of:\n\n\ncat sample.yaml | yaml r - b.c\n\n\n\n\nwill output the value of '2'.\n\n\nSplat\n\n\nGiven a sample.yaml file of:\n\n\n---\nbob:\n item1:\n cats: bananas\n item2:\n cats: apples\n\n\n\n\nthen\n\n\nyaml r sample.yaml bob.*.cats\n\n\n\n\nwill output\n\n\n- bananas\n- apples\n\n\n\n\nHandling '.' in the yaml key\n\n\nGiven a sample.yaml file of:\n\n\nb.x:\n c: 2\n\n\n\n\nthen\n\n\nyaml r sample.yaml \\\nb.x\\\n.c\n\n\n\n\nwill output the value of '2'.\n\n\nArrays\n\n\nYou can give an index to access a specific element:\ne.g.: given a sample file of\n\n\nb:\n e:\n - name: fred\n value: 3\n - name: sam\n value: 4\n\n\n\n\nthen\n\n\nyaml r sample.yaml b.e[1].name\n\n\n\n\nwill output 'sam'\n\n\nArray Splat\n\n\ne.g.: given a sample file of\n\n\nb:\n e:\n - name: fred\n value: 3\n - name: sam\n value: 4\n\n\n\n\nthen\n\n\nyaml r sample.yaml b.e[*].name\n\n\n\n\nwill output:\n\n\n- fred\n- sam",
"text": "yaml r \nyaml_file|json_file\n \npath\n\n\n\n\n\nThis command can take a json file as input too, and will output yaml unless specified to export as json (-j)\n\n\nBasic\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyaml r sample.yaml b.c\n\n\n\n\nwill output the value of '2'.\n\n\nFrom Stdin\n\n\nGiven a sample.yaml file of:\n\n\ncat sample.yaml | yaml r - b.c\n\n\n\n\nwill output the value of '2'.\n\n\nSplat\n\n\nGiven a sample.yaml file of:\n\n\n---\nbob:\n item1:\n cats: bananas\n item2:\n cats: apples\n\n\n\n\nthen\n\n\nyaml r sample.yaml bob.*.cats\n\n\n\n\nwill output\n\n\n- bananas\n- apples\n\n\n\n\nHandling '.' in the yaml key\n\n\nGiven a sample.yaml file of:\n\n\nb.x:\n c: 2\n\n\n\n\nthen\n\n\nyaml r sample.yaml \\\nb.x\\\n.c\n\n\n\n\nwill output the value of '2'.\n\n\nArrays\n\n\nYou can give an index to access a specific element:\ne.g.: given a sample file of\n\n\nb:\n e:\n - name: fred\n value: 3\n - name: sam\n value: 4\n\n\n\n\nthen\n\n\nyaml r sample.yaml b.e[1].name\n\n\n\n\nwill output 'sam'\n\n\nArray Splat\n\n\ne.g.: given a sample file of\n\n\nb:\n e:\n - name: fred\n value: 3\n - name: sam\n value: 4\n\n\n\n\nthen\n\n\nyaml r sample.yaml b.e[*].name\n\n\n\n\nwill output:\n\n\n- fred\n- sam",
"title": "Read"
},
{
@@ -57,7 +57,7 @@
},
{
"location": "/write/",
"text": "yaml w \nyaml file\n \npath\n \nnew value\n\n\n\n\n\nTo Stdout\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyaml w sample.yaml b.c cat\n\n\n\n\nwill output:\n\n\nb:\n c: cat\n\n\n\n\nFrom STDIN\n\n\ncat sample.yaml | yaml w - b.c blah\n\n\n\n\nAdding new fields\n\n\nAny missing fields in the path will be created on the fly.\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyaml w sample.yaml b.d[0] \nnew thing\n\n\n\n\n\nwill output:\n\n\nb:\n c: cat\n d:\n - new thing\n\n\n\n\nUpdating files in-place\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyaml w -i sample.yaml b.c cat\n\n\n\n\nwill update the sample.yaml file so that the value of 'c' is cat.\n\n\nUpdating multiple values with a script\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n e:\n - name: Billy Bob\n\n\n\n\nand a script update_instructions.yaml of:\n\n\nb.c: 3\nb.e[0].name: Howdy Partner\n\n\n\n\nthen\n\n\nyaml w -s update_instructions.yaml sample.yaml\n\n\n\n\nwill output:\n\n\nb:\n c: 3\n e:\n - name: Howdy Partner\n\n\n\n\nAnd, of course, you can pipe the instructions in using '-':\n\n\ncat update_instructions.yaml | yaml w -s - sample.yaml",
"text": "yaml w \nyaml_file|json_file\n \npath\n \nnew value\n\n\n\n\n\nThis command can take a json file as input too, and will output yaml unless specified to export as json (-j)\n\n\nTo Stdout\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyaml w sample.yaml b.c cat\n\n\n\n\nwill output:\n\n\nb:\n c: cat\n\n\n\n\nFrom STDIN\n\n\ncat sample.yaml | yaml w - b.c blah\n\n\n\n\nAdding new fields\n\n\nAny missing fields in the path will be created on the fly.\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyaml w sample.yaml b.d[0] \nnew thing\n\n\n\n\n\nwill output:\n\n\nb:\n c: cat\n d:\n - new thing\n\n\n\n\nUpdating files in-place\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyaml w -i sample.yaml b.c cat\n\n\n\n\nwill update the sample.yaml file so that the value of 'c' is cat.\n\n\nUpdating multiple values with a script\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n e:\n - name: Billy Bob\n\n\n\n\nand a script update_instructions.yaml of:\n\n\nb.c: 3\nb.e[0].name: Howdy Partner\n\n\n\n\nthen\n\n\nyaml w -s update_instructions.yaml sample.yaml\n\n\n\n\nwill output:\n\n\nb:\n c: 3\n e:\n - name: Howdy Partner\n\n\n\n\nAnd, of course, you can pipe the instructions in using '-':\n\n\ncat update_instructions.yaml | yaml w -s - sample.yaml",
"title": "Write/Update"
},
{
@@ -102,18 +102,18 @@
},
{
"location": "/convert/",
"text": "Yaml2json\n\n\nTo convert output to json, use the --tojson (or -j) flag. This can be used with any command.\n\n\njson2yaml\n\n\nTo read in json, use the --fromjson (or -J) flag. This can be used with any command.",
"text": "Yaml to Json\n\n\nTo convert output to json, use the --tojson (or -j) flag. This can be used with any command.\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyaml r -j sample.yaml b.c\n\n\n\n\nwill output\n\n\n{\nb\n:{\nc\n:2}}\n\n\n\n\nJson to Yaml\n\n\nTo read in json, just pass in a json file instead of yaml, it will just work :)\n\n\ne.g given a json file\n\n\n{\na\n:\nEasy! as one two three\n,\nb\n:{\nc\n:2,\nd\n:[3,4]}}\n\n\n\n\nthen\n\n\nyaml r sample.json\n\n\n\n\nwill output\n\n\na: Easy! as one two three\nb:\n c: 2\n d:\n - 3\n - 4",
"title": "Convert"
},
{
"location": "/convert/#yaml2json",
"text": "To convert output to json, use the --tojson (or -j) flag. This can be used with any command.",
"title": "Yaml2json"
"location": "/convert/#yaml-to-json",
"text": "To convert output to json, use the --tojson (or -j) flag. This can be used with any command. Given a sample.yaml file of: b:\n c: 2 then yaml r -j sample.yaml b.c will output { b :{ c :2}}",
"title": "Yaml to Json"
},
{
"location": "/convert/#json2yaml",
"text": "To read in json, use the --fromjson (or -J) flag. This can be used with any command.",
"title": "json2yaml"
"location": "/convert/#json-to-yaml",
"text": "To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file { a : Easy! as one two three , b :{ c :2, d :[3,4]}} then yaml r sample.json will output a: Easy! as one two three\nb:\n c: 2\n d:\n - 3\n - 4",
"title": "Json to Yaml"
}
]
}

View File

@@ -379,9 +379,10 @@
<h1>Read</h1>
<pre><code>yaml r &lt;yaml file&gt; &lt;path&gt;
<pre><code>yaml r &lt;yaml_file|json_file&gt; &lt;path&gt;
</code></pre>
<p>This command can take a json file as input too, and will output yaml unless specified to export as json (-j)</p>
<h3 id="basic">Basic</h3>
<p>Given a sample.yaml file of:</p>
<pre><code class="yaml">b:

View File

@@ -4,7 +4,7 @@
<url>
<loc>/</loc>
<lastmod>2017-04-13</lastmod>
<lastmod>2017-04-19</lastmod>
<changefreq>daily</changefreq>
</url>
@@ -12,7 +12,7 @@
<url>
<loc>/read/</loc>
<lastmod>2017-04-13</lastmod>
<lastmod>2017-04-19</lastmod>
<changefreq>daily</changefreq>
</url>
@@ -20,7 +20,7 @@
<url>
<loc>/write/</loc>
<lastmod>2017-04-13</lastmod>
<lastmod>2017-04-19</lastmod>
<changefreq>daily</changefreq>
</url>
@@ -28,7 +28,7 @@
<url>
<loc>/create/</loc>
<lastmod>2017-04-13</lastmod>
<lastmod>2017-04-19</lastmod>
<changefreq>daily</changefreq>
</url>
@@ -36,7 +36,7 @@
<url>
<loc>/convert/</loc>
<lastmod>2017-04-13</lastmod>
<lastmod>2017-04-19</lastmod>
<changefreq>daily</changefreq>
</url>

View File

@@ -365,9 +365,10 @@
<h1>Write/Update</h1>
<pre><code>yaml w &lt;yaml file&gt; &lt;path&gt; &lt;new value&gt;
<pre><code>yaml w &lt;yaml_file|json_file&gt; &lt;path&gt; &lt;new value&gt;
</code></pre>
<p>This command can take a json file as input too, and will output yaml unless specified to export as json (-j)</p>
<h3 id="to-stdout">To Stdout</h3>
<p>Given a sample.yaml file of:</p>
<pre><code class="yaml">b: