{"id":17954435,"url":"https://github.com/sayanarijit/jf","last_synced_at":"2025-03-25T00:31:59.705Z","repository":{"id":148761965,"uuid":"620945726","full_name":"sayanarijit/jf","owner":"sayanarijit","description":"jf %q \"JSON Formatted\"","archived":false,"fork":false,"pushed_at":"2023-06-01T06:44:33.000Z","size":107,"stargazers_count":31,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-19T05:55:53.833Z","etag":null,"topics":["command-line","command-line-tool","json","yaml"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sayanarijit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sayanarijit","ko_fi":"sayanarijit","liberapay":"sayanarijit"}},"created_at":"2023-03-29T17:23:10.000Z","updated_at":"2025-01-01T01:00:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"73eb96e6-44c6-4459-a968-d7ba7d596181","html_url":"https://github.com/sayanarijit/jf","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayanarijit%2Fjf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayanarijit%2Fjf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayanarijit%2Fjf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayanarijit%2Fjf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sayanarijit","download_url":"https://codeload.github.com/sayanarijit/jf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245377921,"owners_count":20605374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line","command-line-tool","json","yaml"],"created_at":"2024-10-29T10:16:27.931Z","updated_at":"2025-03-25T00:31:59.665Z","avatar_url":"https://github.com/sayanarijit.png","language":"Rust","funding_links":["https://github.com/sponsors/sayanarijit","https://ko-fi.com/sayanarijit","https://liberapay.com/sayanarijit"],"categories":["\u003ca name=\"data-management-json\"\u003e\u003c/a\u003eData management - JSON/YAML/etc."],"sub_categories":[],"readme":"# jf\n\n[![Crate Status](https://img.shields.io/crates/v/jf.svg)](https://crates.io/crates/jf)\n\n[![Packaging status][repos]][repology]\n\n[jf][jf] is a [jo][jo] alternative, A small utility to safely format and print [JSON][json] objects in the commandline.\n\nHowever, unlike `jo`, where you build the JSON object by nesting `jo` outputs,\n`jf` works similar to `printf`, i.e. it expects the template in [YAML][yaml] format as the first argument, and then the values for the placeholders as subsequent arguments.\n\nFor example:\n\n```bash\njf \"{one: %s, two: %q, three: [%(four)s, %(five=5)q]}\" 1 2 four=4\n# {\"one\":1,\"two\":\"2\",\"three\":[4,\"5\"]}\n```\n\n### INSTALL\n\n#### [Cargo][cargo]\n\nAs a CLI tool\n\n```bash\ncargo install jf\n```\n\nOr as a library:\n\n```bash\ncargo add jf\n```\n\n#### [Nixpkgs][nixpkgs]\n\n```bash\nnix-env -f https://github.com/NixOS/nixpkgs/tarball/nixos-unstable -iA jf\n```\n\n#### [Binaries][bins]\n\n### USAGE\n\n```bash\njf [OPTION]... [--] TEMPLATE [VALUE]... [NAME=VALUE]... [NAME@FILE]...\n```\n\n### OPTIONS\n\n| option        | help                                               |\n| ------------- | -------------------------------------------------- |\n| -             | alias for `-f -`, i.e. read template from stdin    |\n| --            | stop parsing CLI options                           |\n| -r, --raw     | print the raw rendered value without formatting    |\n| -p, --pretty  | pretty print the JSON formatted output             |\n| -y, --yaml    | print the output as YAML instead of JSON           |\n| -h, --help    | print this help message                            |\n| -v, --version | print the version number                           |\n| -f, --file    | treat the template argument as a file to read from |\n\n### TEMPLATE\n\nTemplate should render into valid YAML. It can contain the following placeholders:\n\n- `%%` a literal `%` character\n- `%s` `%q` read positional argument\n- `%-s` `%-q` read stdin\n- `%(NAME)s` `%(NAME)q` read named value from argument\n- `%(NAME=DEFAULT)s` `%(NAME=DEFAULT)q` placeholder with default value\n- `%(NAME@FILE)s` `%(NAME@FILE)q` read default value from file path\n- `%(NAME@-)s` `%(NAME@-)q` read default value from stdin\n- `%(NAME?)s` `%(NAME?)q` nullable placeholder that defaults to null\n- `%(NAME)?s` `%(NAME)?q` optional placeholder that defaults to blank\n- `%*s` `%*q` expand positional args as array items\n- `%*-s` `%*-q` expand stdin as array items\n- `%**s` `%**q` expand positional args as key value pairs\n- `%**-s` `%**-q` expand stdin as key value pairs\n- `%(NAME)*s` `%(NAME)*q` expand named args as array items\n- `%(NAME)**s` `%(NAME)**q` expand named args as key value pairs\n\nUse placeholders with suffix `q` for safely quoted JSON string and `s` for JSON values\nother than string.\n\n### RULES\n\n- Pass values for positional placeholders in the same order as in the template.\n- Pass values for named placeholders using `NAME=VALUE` syntax.\n- Pass values for named array items using `NAME=ITEM_N` syntax.\n- Pass values for named key value pairs using `NAME=KEY_N NAME=VALUE_N` syntax.\n- Pass values to stdin following the order and separate them with null byte (`\\0`).\n- Use `NAME@FILE` syntax to read from file where FILE can be `-` for stdin.\n- Do not pass positional values after named values.\n- To allow merging arrays and objects via expansion, trailing comma after `s` and `q`,\n  if any, will be auto removed if no value is passed for the expandable placeholder.\n\n### EXAMPLES\n\n```bash\njf %s 1\n# 1\n\njf %q 1\n# \"1\"\n\njf '{%**q}' one 1 two 2 three 3\n# {\"one\":\"1\",\"two\":\"2\",\"three\":\"3\"}\n\nseq 1 3 | xargs printf '%s\\0' | jf '[%*-s]'\n# [1,2,3]\n\njf \"{%q: %(value=default)q, %(bar)**q}\" foo value=bar bar=biz bar=baz\n# {\"foo\":\"bar\",\"biz\":\"baz\"}\n\njf \"{str or bool: %(str)?q %(bool)?s, nullable: %(nullable?)q}\" str=true\n# {\"str or bool\":\"true\",\"nullable\":null}\n\njf '{1: %s, two: %q, 3: %(3)s, four: %(four=4)q, \"%%\": %(pct?)q}' 1 2 3=3\n# {\"1\":1,\"two\":\"2\",\"3\":3,\"four\":\"4\",\"%\":null}\n```\n\n### SHELL ALIASES\n\nYou can set the following aliases in your shell:\n\n```bash\nalias str='jf %q'\nalias arr='jf \"[%*s]\"'\nalias obj='jf \"{%**s}\"'\n```\n\nThen you can use them like this:\n\n```bash\nstr 1\n# \"1\"\n\narr 1 2 3\n# [1,2,3]\n\nobj one 1 two 2 three 3\n# {\"one\":1,\"two\":2,\"three\":3}\n\nobj 1 2 3 $(arr 4 $(str 5))\n# {\"1\":2,\"3\":[4,\"5\"]}\n```\n\n### RUST LIBRARY\n\n```rust\nlet json = match jf::format([\"%q\", \"JSON Formatted\"].map(Into::into)) {\n    Ok(value) =\u003e value,\n    Err(jf::Error::Jf(e)) =\u003e bail!(\"mytool: {e}\"),\n    Err(jf::Error::Json(e)) =\u003e bail!(\"mytool: json: {e}\"),\n    Err(jf::Error::Yaml(e)) =\u003e bail!(\"mytool: yaml: {e}\"),\n};\n```\n\n[jf]: https://github.com/sayanarijit/jf\n[jo]: https://github.com/jpmens/jo\n[yaml]: https://yaml.org\n[json]: https://json.org\n[bins]: https://github.com/sayanarijit/jf/releases/latest\n[cargo]: https://crates.io/crates/jf\n[nixpkgs]: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/development/tools/jf/default.nix\n[repology]: https://repology.org/project/jf/versions\n[repos]: https://repology.org/badge/vertical-allrepos/jf.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayanarijit%2Fjf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsayanarijit%2Fjf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayanarijit%2Fjf/lists"}