jf
jf is a jo alternative, A small utility to safely format and print JSON objects in the commandline.
However, unlike jo, where you build the JSON object by nesting jo outputs,
jf works similar to printf, i.e. it expects the template in YAML format as the first argument, and then the values for the placeholders as subsequent arguments.
INSTALL
Cargo
As a CLI tool
Or as a library:
Nixpkgs
Binaries
USAGE
Where TEMPLATE may contain the following placeholders:
%qquoted and safely escaped JSON string.%sJSON values other than string.%vthejfversion number.%%a literal%character.
And [VALUE]... [NAME=VALUE]... are the values for the placeholders.
SYNTAX
%s,%qposiitonal placeholder.%(NAME)s,%(NAME)qnamed placeholder.%(NAME=DEFAULT)s,%(NAME=DEFAULT)qplaceholder with default value.%(NAME)?s,%(NAME)?qplaceholder with optional value.%*s,%*qexpand positional values as array items.%**s,%**qexpand positional values as key value pairs.%(NAME)*s,%(NAME)*qexpand named values as array items.%(NAME)**s,%(NAME)**qexpand named values as key value pairs.
RULES
- Pass values for positional placeholders in the same order as in the template.
- Pass values for named placeholders using
NAME=VALUEsyntax. - Pass values for named array items using
NAME=ITEM_Nsyntax. - Pass values for named key value pairs using
NAME=KEY_N NAME=VALUE_Nsyntax. - Optional placeholders default to empty string, which is considered as null.
- Do not declare or pass positional placeholders or values after named ones.
- Expandable positional placeholder should be the last placeholder in a template.
EXAMPLES
# 1
# "1"
# [1,2,3]
# {"one":"1","two":"2","three":"3"}
# {"foo":"bar","biz":"baz"}
# {"str_or_bool":"true","optional":null}
# {"1":1,"two":"2","3":3,"four":"4","%":"100%"}
Rust Library
let json = match format ;