NAME
dnk - inspect and modify nested JSON, YAML, and optional Bedrock XML documents
SYNOPSIS
dnk [options] get [key]
dnk [options] set key value [key value ...]
# Read a nested value from a file
dnk -i config.json get database.host
# Read a value from standard input
cat response.json | dnk get .Listeners[0].ListenerArn
# Print an updated document without modifying the input file
dnk -i config.json set database.host localhost
# Replace the input document
dnk -i config.json --replace set database.host localhost
# Replace the input and retain a backup
dnk -i config.json --backup bak set database.host localhost
# Update a Bedrock XML configuration (requires Bedrock::XML)
dnk -r -i /path/to/config/tagx.xml set BEDROCK_SESSION_MANAGER UserSession
# Convert JSON to YAML while modifying a value
dnk -i config.json --output-format yaml set database.host localhost
DESCRIPTION
dnk provides command-line access to nested JSON and YAML data using Data::NestedKey. Keys are expressed as dot-separated paths; array subscripts such as items[0].name and [0].name are supported by get. The set command uses the key syntax supported by Data::NestedKey::set, which does not accept array subscripts.
Input is read from --infile or standard input. Without an explicit --format, dnk recognizes .xml files and Bedrock XML markup; otherwise it attempts JSON decoding first, followed by YAML. The optional Bedrock::XML module is loaded only when XML is used. The top-level document must be a hash or array.
COMMANDS
get [key]
Print the value at key. If omitted, key defaults to ., meaning the entire document. A leading dot may also be used for a nested key.
Scalar values are printed directly. Hashes and arrays are printed as pretty-printed JSON, including when the input was YAML. An undefined or missing value produces empty output by default; --error-on-undefined turns it into an error.
set key value [key value ...]
Apply one or more key/value updates. Data::NestedKey::set supports plain dot-separated paths as well as + and - prefixes for its append/merge and removal operations. Array subscripts are not supported by set.
By default, set prints the modified document to standard output in the input format. --output-format selects a different output format. For XML input, the default output is Bedrock XML. Use --format xml to select Bedrock XML explicitly when necessary.
set does not modify its input file unless replacement is requested. Use --replace to write it back, or --backup EXT to save the original before replacing it. Replacement requires an input filename; standard input cannot be replaced in place.
OPTIONS
- -i, --infile FILE
-
Read from
FILE. If omitted, or ifFILEis-, read from standard input. - -f, --format FORMAT
-
Decode using
json,yaml,yml, orxml. Without this option,.xmlfiles and Bedrock XML input are recognized; otherwise JSON is tried before YAML. XML requires Bedrock::XML, an optional dependency. - -o, --output-format FORMAT
-
Serialize
setoutput asjson,yaml,yml, orxml. If omitted, preserve the decoded input format. XML output requires Bedrock::XML. Use--output-formatto convert between JSON and YAML independently of--format. In-place format conversion replaces the original file's contents but does not rename its extension. - -r, --replace
-
With
set, replace the input file rather than printing the modified document. Requires--infilewith a filename. - -b, --backup EXT
-
With
set, retain the original input under a filename with extensionEXTand replace the input file. Implies--replace. Existing backup files are not overwritten. - -u, --error-on-undefined
-
Make
getfail when the requested key is undefined or missing, rather than printing an empty value. - -h, --help
-
Display command-line help.
EXAMPLES
# Inspect a nested value
dnk -i config.json get database.host
# Print an updated document to STDOUT
dnk -i config.json set database.host localhost
# Update the original document
dnk -i config.json -r set database.host localhost
# Preserve a backup while updating the original
dnk -i config.json -b bak set database.host localhost
# Output the entire document (formatted as JSON)
cat policy.yaml | dnk get .
# Replace a Bedrock XML configuration value
dnk -r -i "$BEDROCK_WEB_DIR/config/tagx.xml" set BEDROCK_SESSION_MANAGER UserSession
# Change a JSON configuration and emit YAML instead
dnk -i config.json -o yaml set database.host localhost
SEE ALSO
Data::NestedKey, JSON, YAML::XS, Bedrock::XML (optional)