{ "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", "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.", "title": "yaml" }, { "location": "/#download-latest-binary", "text": "", "title": "download latest binary" }, { "location": "/#get-the-source", "text": "go get github.com/mikefarah/yaml .zip or tar.gz View on GitHub", "title": "get the source" }, { "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", "title": "Read" }, { "location": "/read/#basic", "text": "Given a sample.yaml file of: b:\n c: 2 then yaml r sample.yaml b.c will output the value of '2'.", "title": "Basic" }, { "location": "/read/#from-stdin", "text": "Given a sample.yaml file of: cat sample.yaml | yaml r - b.c will output the value of '2'.", "title": "From Stdin" }, { "location": "/read/#splat", "text": "Given a sample.yaml file of: ---\nbob:\n item1:\n cats: bananas\n item2:\n cats: apples then yaml r sample.yaml bob.*.cats will output - bananas\n- apples", "title": "Splat" }, { "location": "/read/#handling-in-the-yaml-key", "text": "Given a sample.yaml file of: b.x:\n c: 2 then yaml r sample.yaml \\ b.x\\ .c will output the value of '2'.", "title": "Handling '.' in the yaml key" }, { "location": "/read/#arrays", "text": "You can give an index to access a specific element:\ne.g.: given a sample file of b:\n e:\n - name: fred\n value: 3\n - name: sam\n value: 4 then yaml r sample.yaml b.e[1].name will output 'sam'", "title": "Arrays" }, { "location": "/read/#array-splat", "text": "e.g.: given a sample file of b:\n e:\n - name: fred\n value: 3\n - name: sam\n value: 4 then yaml r sample.yaml b.e[*].name will output: - fred\n- sam", "title": "Array Splat" }, { "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", "title": "Write/Update" }, { "location": "/write/#to-stdout", "text": "Given a sample.yaml file of: b:\n c: 2 then yaml w sample.yaml b.c cat will output: b:\n c: cat", "title": "To Stdout" }, { "location": "/write/#from-stdin", "text": "cat sample.yaml | yaml w - b.c blah", "title": "From STDIN" }, { "location": "/write/#adding-new-fields", "text": "Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b:\n c: 2 then yaml w sample.yaml b.d[0] new thing will output: b:\n c: cat\n d:\n - new thing", "title": "Adding new fields" }, { "location": "/write/#updating-files-in-place", "text": "Given a sample.yaml file of: b:\n c: 2 then yaml w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat.", "title": "Updating files in-place" }, { "location": "/write/#updating-multiple-values-with-a-script", "text": "Given a sample.yaml file of: b:\n c: 2\n e:\n - name: Billy Bob and a script update_instructions.yaml of: b.c: 3\nb.e[0].name: Howdy Partner then yaml w -s update_instructions.yaml sample.yaml will output: b:\n c: 3\n e:\n - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yaml w -s - sample.yaml", "title": "Updating multiple values with a script" }, { "location": "/create/", "text": "Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file.\n\n\nyaml n \npath\n \nnew value\n\n\n\n\n\nCreating a simple yaml file\n\n\nyaml n b.c cat\n\n\n\n\nwill output:\n\n\nb:\n c: cat\n\n\n\n\nCreating using a create script\n\n\nCreate scripts follow the same format as the update scripts.\n\n\nGiven a script create_instructions.yaml of:\n\n\nb.c: 3\nb.e[0].name: Howdy Partner\n\n\n\n\nthen\n\n\nyaml n -s create_instructions.yaml\n\n\n\n\nwill output:\n\n\nb:\n c: 3\n e:\n - name: Howdy Partner\n\n\n\n\nYou can also pipe the instructions in:\n\n\ncat create_instructions.yaml | yaml n -s -", "title": "Create" }, { "location": "/create/#creating-a-simple-yaml-file", "text": "yaml n b.c cat will output: b:\n c: cat", "title": "Creating a simple yaml file" }, { "location": "/create/#creating-using-a-create-script", "text": "Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3\nb.e[0].name: Howdy Partner then yaml n -s create_instructions.yaml will output: b:\n c: 3\n e:\n - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yaml n -s -", "title": "Creating using a create script" }, { "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.", "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/#json2yaml", "text": "To read in json, use the --fromjson (or -J) flag. This can be used with any command.", "title": "json2yaml" } ] }