Skip to content

Set value at existing path


Consider the example input YAML file:

conf.yaml
1
2
3
4
root_node:
  level_one:
    pswd: password
    usr: name

To set a value in a document, the key needs be to a path, along with a value.

cat conf.yaml | rickle obj set /root_node/level_one/pswd **********

This will set the pswd value to ********** and print the whole document with new value to the command line.

root_node:
  level_one:
     pswd: '*********'
     usr: name

Note

If the --output option in obj is used to output to a file, the result is not printed to screen.

For example, the following will output to a file:

cat conf.yaml | rickle --output-type JSON obj --output conf.json set /root_node/level_one/pswd *********
conf.json
{"root_node": {"level_one": {"usr": "name", "pswd": "*********"}}}

Of course this could also be directed:

cat conf.yaml | rickle --output-type JSON obj > conf.json

Note

Values can only be set for paths that exist. To create a new path, use put.

This will, however, not work in the following example and result in an error:

cat conf.yaml | rickle obj set /root_node/level_one/unknown/email not@home.com

Which results in the error message:

error: The path /root_node/level_one/unknown/email could not be traversed

Troubleshooting

The most likely problem to occur is if the path can not be traversed, i.e. the path is incorrect:

error: The path /root_node/level_one/unknown/email could not be traversed