{"id":20693083,"url":"https://github.com/alexobviously/nice_json","last_synced_at":"2026-02-25T01:34:48.250Z","repository":{"id":65919648,"uuid":"602393372","full_name":"alexobviously/nice_json","owner":"alexobviously","description":"A nice way to encode nice maps into nice-looking json.","archived":false,"fork":false,"pushed_at":"2025-02-18T09:56:49.000Z","size":11,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T23:55:52.356Z","etag":null,"topics":["dart","json"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/nice_json","language":"Dart","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/alexobviously.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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-02-16T05:30:52.000Z","updated_at":"2025-02-18T09:56:52.000Z","dependencies_parsed_at":"2025-04-15T10:46:48.048Z","dependency_job_id":null,"html_url":"https://github.com/alexobviously/nice_json","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alexobviously/nice_json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexobviously%2Fnice_json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexobviously%2Fnice_json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexobviously%2Fnice_json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexobviously%2Fnice_json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexobviously","download_url":"https://codeload.github.com/alexobviously/nice_json/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexobviously%2Fnice_json/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29807973,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-24T22:43:48.403Z","status":"ssl_error","status_checked_at":"2026-02-24T22:43:18.536Z","response_time":75,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["dart","json"],"created_at":"2024-11-16T23:25:19.479Z","updated_at":"2026-02-25T01:34:48.202Z","avatar_url":"https://github.com/alexobviously.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nice JSON!\n\nThis is a simple little library for printing human-readable JSON that looks a little bit nicer than the stuff you get out of the default encoder.\n\n## The Problem\n---\nThe behaviour of the standard json encoder can often lead to sprawling files full of newlines and single integers on lines, for example:\n\n```dart\nfinal data = {\n  'a': [0, 1],\n  'b': [\n    [0, 1],\n    [2, 3]\n  ]\n};\nString json = JsonEncoder.withIndent(' ').convert(data);\nprint(json);\n```\n\nGives you something like this:\n\n```json\n{\n \"a\": [\n  0,\n  1\n ],\n \"b\": [\n  [\n   0,\n   1\n  ],\n  [\n   2,\n   3\n  ]\n ]\n}\n```\n\nThis is obviously valid json, but not much fun to read.\n\n## The Solution\n---\nHow about this instead:\n\n```dart\nString json = niceJson(data);\nprint(json);\n```\n-\u003e\n```json\n{\n \"a\": [0, 1],\n \"b\": [[0, 1], [2, 3]]\n}\n```\n\nNice JSON!\n\n## Features \u0026 Parameters\n---\n### Max Content Length \u0026 Max Line Length\nThese are pretty straightforward.\n`maxContentLength` defines the maximum length a single entry's value can be.\n`maxLineLength` defines the maximum length an entire line can be, including indent and key.\nIf either of these is exceeded when building the compressed encoding of a value, it will be expanded.\n\n### Minimum Depth\n`minDepth` is the minimum depth that must be reached before values start getting compressed. By default, this is 1, meaning the whole JSON representation cannot simply be a single line, but anything after the root level is compressed.\nIf you set this to 2, for example, you can achieve this behaviour:\n\n```dart\nfinal data = {\n  'a': {'hello': 'world'},\n  'foo': {'bar': 1, 'baz': 2},\n  'b': [\n    [0, 1],\n    2,\n    3,\n  ],\n};\nString json = niceJson(data, minDepth: 2);\n```\n-\u003e\n```json\n{\n \"a\": {\n  \"hello\": \"world\"\n },\n \"foo\": {\n  \"bar\": 1,\n  \"baz\": 2\n },\n \"b\": [\n  [0, 1],\n  2,\n  3\n ]\n}\n```\n\nInstead of what you would get with `minDepth: 1`:\n```json\n{\n \"a\": {\"hello\": \"world\"},\n \"foo\": {\"bar\": 1, \"baz\": 2},\n \"b\": [[0, 1], 2, 3]\n}\n```\n\n### Always Expand Specific Keys\n`alwaysExpandKeys` takes a `List\u003cString\u003e` of key names that should always have their values expanded, regardless of length.\n\ne.g.:\n```dart\nfinal data = {\n  'a': {'hello': 'world'},\n  'b': {'foo': 'bar'},\n};\nString json = niceJson(data, alwaysExpandKeys: ['b']);\n```\n-\u003e\n```json\n{\n \"a\": {\"hello\": \"world\"},\n \"b\": {\n  \"foo\": \"bar\"\n }\n}\n```\n\nInstead of:\n```json\n{\n \"a\": {\"hello\": \"world\"},\n \"b\": {\"foo\": \"bar\"}\n}\n```\n\nIt's possible to access nested keys with dot notation too. Take this data:\n\n```dart\nMap\u003cString, dynamic\u003e data = {\n  'a': {\n    'x': [1, 2],\n    'y': [3, 4],\n  },\n  'b': {\n    'x': [5, 6],\n    'y': [7, 8],\n  },\n};\nString json = niceJson(data, minDepth: 2, alwaysExpandKeys: ['a.x']);\n```\n-\u003e\n```json\n{\n \"a\": {\n  \"x\": [\n   1,\n   2\n  ],\n  \"y\": [3, 4]\n },\n \"b\": {\n  \"x\": [5, 6],\n  \"y\": [7, 8]\n }\n}\n```\n\nOr with a wildcard:\n```dart\nString json = niceJson(data, minDepth: 2, alwaysExpandKeys: ['*.x']);\n```\n-\u003e\n```json\n{\n \"a\": {\n  \"x\": [\n   1,\n   2\n  ],\n  \"y\": [3, 4]\n },\n \"b\": {\n  \"x\": [\n   5,\n   6\n  ],\n  \"y\": [7, 8]\n }\n}\n```\nA double wildcard (`**`) can be used to match multiple levels. For example, `a.*.e` would not match `a.b.c.d.e`, but `a.**.e` would.\n\nList indices also work:\n```dart\nMap\u003cString, dynamic\u003e data = {\n  'a': [\n    [0, 1, 2],\n    [3, 4, 5],\n  ],\n  'b': [\n    [0, 1],\n    [2, 3],\n  ],\n};\nString json = niceJson(data, minDepth: 2, alwaysExpandKeys: ['*.0']);\n```\n-\u003e\n```json\n{\n \"a\": [\n  [\n   0,\n   1,\n   2\n  ],\n  [3, 4, 5]\n ],\n \"b\": [\n  [\n   0,\n   1\n  ],\n  [2, 3]\n ]\n}\n```\n\n## Upcoming Features\n---\n### Maximum Nesting\n\nA desirable feature would be to only allow a certain amount of nesting on a single line, for example:\n```json\n{\n \"a\": [0, 1],\n \"b\": [\n  [0, 1],\n  [2, 3]\n ]\n}\n```\n\nThis will probably be added after Dart 3.0 because it would be nice to do this sort of thing with records.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexobviously%2Fnice_json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexobviously%2Fnice_json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexobviously%2Fnice_json/lists"}