{"id":18085054,"url":"https://github.com/jwodder/serde-json-fmt","last_synced_at":"2025-04-06T00:14:19.456Z","repository":{"id":153156746,"uuid":"628274874","full_name":"jwodder/serde-json-fmt","owner":"jwodder","description":"Configurable formatting for serde_json serialization","archived":false,"fork":false,"pushed_at":"2024-02-10T18:11:54.000Z","size":53,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-10T22:27:23.568Z","etag":null,"topics":["available-on-crates-io","json","rust","serde","serde-json"],"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/jwodder.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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}},"created_at":"2023-04-15T12:51:01.000Z","updated_at":"2024-02-04T16:24:31.000Z","dependencies_parsed_at":"2023-10-10T17:24:24.392Z","dependency_job_id":"abb49cb4-7cf2-4f84-ab29-8d9fc2413761","html_url":"https://github.com/jwodder/serde-json-fmt","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwodder%2Fserde-json-fmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwodder%2Fserde-json-fmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwodder%2Fserde-json-fmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwodder%2Fserde-json-fmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwodder","download_url":"https://codeload.github.com/jwodder/serde-json-fmt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415966,"owners_count":20935387,"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":["available-on-crates-io","json","rust","serde","serde-json"],"created_at":"2024-10-31T15:09:13.711Z","updated_at":"2025-04-06T00:14:19.434Z","avatar_url":"https://github.com/jwodder.png","language":"Rust","readme":"[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n[![CI Status](https://github.com/jwodder/serde-json-fmt/actions/workflows/test.yml/badge.svg)](https://github.com/jwodder/serde-json-fmt/actions/workflows/test.yml)\n[![codecov.io](https://codecov.io/gh/jwodder/serde-json-fmt/branch/master/graph/badge.svg)](https://codecov.io/gh/jwodder/serde-json-fmt)\n[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.70-orange)](https://www.rust-lang.org)\n[![MIT License](https://img.shields.io/github/license/jwodder/serde-json-fmt.svg)](https://opensource.org/licenses/MIT)\n\n[GitHub](https://github.com/jwodder/serde-json-fmt) | [crates.io](https://crates.io/crates/serde-json-fmt) | [Documentation](https://docs.rs/serde-json-fmt) | [Issues](https://github.com/jwodder/serde-json-fmt/issues) | [Changelog](https://github.com/jwodder/serde-json-fmt/blob/master/CHANGELOG.md)\n\nThe `serde-json-fmt` crate lets you create custom\n[`serde_json`](https://crates.io/crates/serde_json) formatters with the\nindentation, separators, and ASCII requirements of your choice.\n\n`serde_json` itself only directly provides the ability to produce JSON in\neither \"compact\" form or \"pretty\" form, with the only customizable aspect being\nthe string used for pretty indentation.  `serde-json-fmt` complements\n`serde_json` to let you also customize the whitespace around commas \u0026 colons\nand whether to escape non-ASCII characters.\n\nExamples\n========\n\nSay you want to serialize a value in one-line \"compact\" form, but you want a\nspace after each colon \u0026 comma, something that `serde_json`'s compact form\ndoesn't do.  `serde-json-fmt` lets you do that:\n\n```rust\nuse serde_json::json;\nuse serde_json_fmt::JsonFormat;\n\nlet value = json!({\n    \"colors\": [\"red\", \"blue\", \"taupe\"],\n    \"sub\": {\n        \"name\": \"Foo\",\n        \"on\": true,\n        \"size\": 17\n    }\n});\n\nlet s = JsonFormat::new()\n    .comma(\", \")\n    .unwrap()\n    .colon(\": \")\n    .unwrap()\n    .format_to_string(\u0026value)\n    .unwrap();\n\nassert_eq!(\n    s,\n    r#\"{\"colors\": [\"red\", \"blue\", \"taupe\"], \"sub\": {\"name\": \"Foo\", \"on\": true, \"size\": 17}}\"#\n);\n```\n\nSay you want to format a value in multiline \"pretty\" form, but using four-space\nindents and with all non-ASCII characters encoded as `\\uXXXX` escape sequences.\n`serde-json-fmt` lets you do that:\n\n```rust\nuse serde_json::json;\nuse serde_json_fmt::JsonFormat;\n\nlet value = json!({\n    \"emojis\": {\n        \"goat\":\"🐐\",\n        \"pineapple\": \"🍍\",\n        \"smile\": \"😀\",\n    },\n    \"greek\": {\n        \"α\": \"alpha\",\n        \"β\": \"beta\",\n        \"γ\": \"gamma\",\n    }\n});\n\nlet s = JsonFormat::pretty()\n    .indent_width(Some(4))\n    .ascii(true)\n    .format_to_string(\u0026value)\n    .unwrap();\n\nassert_eq!(s, r#\"{\n    \"emojis\": {\n        \"goat\": \"\\ud83d\\udc10\",\n        \"pineapple\": \"\\ud83c\\udf4d\",\n        \"smile\": \"\\ud83d\\ude00\"\n    },\n    \"greek\": {\n        \"\\u03b1\": \"alpha\",\n        \"\\u03b2\": \"beta\",\n        \"\\u03b3\": \"gamma\"\n    }\n}\"#);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwodder%2Fserde-json-fmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwodder%2Fserde-json-fmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwodder%2Fserde-json-fmt/lists"}