{"id":16621289,"url":"https://github.com/djj123dj/formatted-json-stringify","last_synced_at":"2026-04-25T10:02:34.207Z","repository":{"id":249312551,"uuid":"831168087","full_name":"DJj123dj/formatted-json-stringify","owner":"DJj123dj","description":"An advanced \u0026 customisable version of the javascript JSON.stringify() function!","archived":false,"fork":false,"pushed_at":"2026-04-18T17:03:38.000Z","size":29,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-18T17:13:43.128Z","etag":null,"topics":["beautifier","config","dashboard","formatter","javascript","json","json-auto-fill","json-database","json-formatter","json-formatting","json-stringify","nodejs","stringify","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/formatted-json-stringify","language":"TypeScript","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/DJj123dj.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2024-07-19T20:33:49.000Z","updated_at":"2026-04-18T17:02:30.000Z","dependencies_parsed_at":"2024-07-20T01:40:26.563Z","dependency_job_id":null,"html_url":"https://github.com/DJj123dj/formatted-json-stringify","commit_stats":null,"previous_names":["djj123dj/formatted-json-stringify"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/DJj123dj/formatted-json-stringify","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DJj123dj%2Fformatted-json-stringify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DJj123dj%2Fformatted-json-stringify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DJj123dj%2Fformatted-json-stringify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DJj123dj%2Fformatted-json-stringify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DJj123dj","download_url":"https://codeload.github.com/DJj123dj/formatted-json-stringify/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DJj123dj%2Fformatted-json-stringify/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32257755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T09:15:33.318Z","status":"ssl_error","status_checked_at":"2026-04-25T09:15:31.997Z","response_time":59,"last_error":"SSL_read: 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":["beautifier","config","dashboard","formatter","javascript","json","json-auto-fill","json-database","json-formatter","json-formatting","json-stringify","nodejs","stringify","typescript"],"created_at":"2024-10-12T02:46:55.879Z","updated_at":"2026-04-25T10:02:34.194Z","avatar_url":"https://github.com/DJj123dj.png","language":"TypeScript","readme":"\u003cpicture\u003e\n   \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://apis.dj-dj.be/cdn/formatted-json-stringify/logo-dark.png\"\u003e\n   \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://apis.dj-dj.be/cdn/formatted-json-stringify/logo.png\"\u003e\n   \u003cimg src=\"https://apis.dj-dj.be/cdn/formatted-json-stringify/logo.png\" alt=\"Formatted Json Stringify\" width=\"600px\"\u003e\n\u003c/picture\u003e\n\n[![discord](https://img.shields.io/badge/discord-join%20our%20server-5865F2.svg?style=flat-square\u0026logo=discord)](https://discord.com/invite/26vT9wt3n3)  [![version](https://img.shields.io/badge/version-1.3.1-brightgreen.svg?style=flat-square)](https://github.com/DJj123dj/formatted-json-stringify/releases/tag/v1.3.1)  [![license](https://img.shields.io/badge/license-MIT-important.svg?style=flat-square)](https://github.com/DJj123dj/formatted-json-stringify/blob/main/LICENSE) [![stars](https://img.shields.io/github/stars/DJj123dj/formatted-json-stringify?color=yellow\u0026label=stars\u0026logo=github\u0026style=flat-square)](https://www.github.com/DJj123dj/formatted-json-stringify)\n\n### Formatted Json Stringify\nFormatted Json Stringify is a small [npm package](https://www.npmjs.com/package/formatted-json-stringify) which upgrades `JSON.stringify()` with many new formatting tools! Add comments to JSON files, output multi-line \u0026 single-line JSON at the same time and so much more! If you're having trouble configuring the library, feel free to join our support server and we will help you further! \n\n### [Install it using npm!](https://www.npmjs.com/package/formatted-json-stringify)\n```\nnpm i formatted-json-stringify\n```\n\n## 📌 Features\n- ✏️ Supports JSONC comments\n- ⚖️ Lightweight\n- ✅ Typescript compatible\n- ⚙️ Advanced customisability\n- 📄 Create custom formatters\n- ⭐️ Compact \u0026 multiline JSON work together\n\n## 🛠️ Usage\n```js\nconst fjs = require(\"formatted-json-stringify\") //import fjs from \"formatted-json-stringify\"\nconst fs = require(\"fs\")                        //import fs from \"fs\"\n\n//Our JSON data sample\nconst sample = {\n    property1:\"this is the first property\",\n    property2:\"this is the second property\",\n    property3:123,\n    subObject:{\n        sub_property_1:true,\n        sub_property_2:false,\n        sub_array:[\"abcd\",\"efg\",\"hijk\",\"lmnop\",\"qrst\",\"uvw\",\"xyz\"]\n    }\n}\n\n//let's create the formatter for our sample\nconst formatter = new fjs.ObjectFormatter(null,true,[\n    new fjs.PropertyFormatter(\"property1\"),\n    new fjs.PropertyFormatter(\"property2\"),\n    new fjs.PropertyFormatter(\"property3\"),\n    new fjs.TextFormatter(), //let's add a space inbetween\n    new fjs.ObjectFormatter(\"subObject\",true,[\n        new fjs.PropertyFormatter(\"sub_property_1\"),\n        new fjs.PropertyFormatter(\"sub_property_2\"),\n        new fjs.TextFormatter(), //let's add another space inbetween :)\n        new fjs.SingleCommentFormatter(\"Hi there! I'm a comment!\"),\n        new fjs.ArrayFormatter(\"sub_array\",false,new fjs.PropertyFormatter(null)),\n    ]),\n])\n\n//and finally write the output to a json file\nfs.writeFileSync(\"./test/output.json\",formatter.stringify(sample))\n```\n\n### Expected Output:\n```jsonc\n{\n    \"property1\":\"this is the first property\",\n    \"property2\":\"this is the second property\",\n    \"property3\":123,\n    \n    \"subObject\":{\n        \"sub_property_1\":true,\n        \"sub_property_2\":false,\n        \n        //Hi there! I'm a comment!\n        \"sub_array\":[\"abcd\",\"efg\",\"hijk\",\"lmnop\",\"qrst\",\"uvw\",\"xyz\",\"and thats the alphabet!\"]\n    }\n}\n```\n\u003e You can clearly see an empty newline between `property3` and `subObject`. This is also the case with the `sub_property_2`! \n\nYou're also able to change if an array/object is rendered `inline` or `multiline`. For small arrays \u0026 objects, it's recommended to use the `inline` variant!\n\n\n## 📦 Classes\nWhen using Formatted Json Stringify you have access to the following classes.\n\n|Class                   |Variable Type                          |Functionality                                                                                                                            |\n|------------------------|---------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|\n|`PropertyFormatter`     |`boolean`, `string`, `number` \u0026 `null` |Format any [primitive](https://www.geeksforgeeks.org/primitive-and-non-primitive-data-types-in-javascript/) variable except `undefined`! |\n|`ObjectFormatter`       |`object`                               |Format an `object` and customise how it's children/properties are formatted! **This supports multiple formatters for all children!**     |\n|`ArrayFormatter`        |`array`                                |Format an `array` and customise how the values are formatted. **This supports 1 formatter for all children!**!                           |\n|`TextFormatter`         |`/`                                    |Add an empty row or note between properties in an `object`!                                                                              |\n|`SingleCommentFormatter`|`/`                                    |Add a single-line `//...` comment between 2 properties. Can also be used inside another formatter for inline comments.                   |\n|`MultiCommentFormatter` |`/`                                    |Add a single-line `/*...*/` comment between 2 properties. Can also be used inside another formatter for inline comments.                 |\n|`ObjectSwitchFormatter` |`object`                               |Use this utility class to switch `ObjectFormatter`'s based on a `key` and `value` match in the object.                                   |\n|`DefaultFormatter`      |`any`                                  |Format any variable with unknown contents! This will just use the default `JSON.stringify()` method!                                     |\n\n\u003e There is also the abstract `BaseFormatter` class for creating a custom formatter!\n\n### Configurable Options\nHere, you can find a list of settings found on most formatters and what they will do.\n|Option               |Availability                         |Type                 |Functionality                                                                                                         |\n|---------------------|-------------------------------------|---------------------|----------------------------------------------------------------------------------------------------------------------|\n|`name`               |All Formatters                       |`string\\|null`       |When not `null`, it renders the property name or key. [Click here for an example!](#example-2-name-vs-without-name)   |\n|`multiline`          |`ObjectFormatter` \u0026 `ArrayFormatter` |`boolean`            |When `true`, it renders the object or array `multiline`. [Click here for an example!](#example-1-multiline-vs-inline) |\n|`space`              |`ObjectFormatter` \u0026 `ArrayFormatter` |`string\\|undefined`  |Used as indentation when `multiline` is enabled. 4 spaces by default.                                                 |\n|`multilineWhenEmpty` |`ObjectFormatter` \u0026 `ArrayFormatter` |`boolean\\|undefined` |When enabled, `multiline` will still be used even if the object/array is empty.                                       |\n|`text`               |`TextFormatter`                      |`string\\|undefined`  |When used, insert custom text on this row. Can be used for comments. When not defined, it will just be an empty row.  |\n|`children`           |`ObjectFormatter`                    |`BaseFormatter[]`    |A list of formatters which will define how all children/properties of the object are formatted.                       |\n|`property`           |`ArrayFormatter`                     |`BaseFormatter`      |The formatter used to format the properties/values of this array.                                                     |\n|`formatters`         |`ObjectSwitchFormatter`              |`ObjectSwitchData[]` |A list of `ObjectFormatter`'s to choose from, depending on a key-value match.                                         |\n|`comment`            |All Formatters                       |`CommentFormatter`   |Specify an optional inline comment. It will be rendered after the JSON data.                                          |\n\n## 📸 Example Usage\n### Example 1: Multiline VS Inline\n\u003e Here, we will compare a `multiline` format vs an `inline` format. It's recommended to use the `multiline` format for large `objects` and `arrays`!\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003eInline (objects: inline, array: multiline)\u003c/td\u003e\n\u003ctd\u003eMultiline (objects: multiline, array: multiline)\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```json\n[\n    {\"key\":\"sample-key-1\",\"value\":\"hello world!\"},\n    {\"key\":\"sample-key-2\",\"value\":\"hello mars!\"},\n    {\"key\":\"sample-key-3\",\"value\":\"hello venus!\"},\n    {\"key\":\"sample-key-4\",\"value\":\"hello sun!\"}\n]\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```json\n[\n    {\n        \"key\":\"sample-key-1\",\n        \"value\":\"hello world!\"\n    },\n    {\n        \"key\":\"sample-key-2\",\n        \"value\":\"hello mars!\"\n    },\n    {\n        \"key\":\"sample-key-3\",\n        \"value\":\"hello venus!\"\n    },\n    {\n        \"key\":\"sample-key-4\",\n        \"value\":\"hello sun!\"\n    }\n]\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n### Example 2: Name VS Without Name\n\u003e Here, we will compare what will happen when you set the `name` property to `null` or a `string`!\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003eName\u003c/td\u003e\n\u003ctd\u003eWithout Name\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```json\n\"thisIsTheName\":{\n    \"property1\":1,\n    \"property2\":2,\n    \"property3\":3\n}\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```json\n{\n    \"property1\":1,\n    \"property2\":2,\n    \"property3\":3\n}\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\nThe only place where you should disable the `name` is in the **first formatter** or in **array properties**!\n\n### Example 3: Using Object Switch For Databases\n\u003e We're creating a database with 1 simple type and 1 complex type.\n\u003e The complex type is formatted `multiline` while the simple type is formatted `inline`!\n```js\nconst input = [\n    {type:\"simple\",key:\"sample-key-1\",value:\"hello world!\"},\n    {type:\"simple\",key:\"sample-key-2\",value:\"hello mars!\"},\n    {type:\"complex\",module:\"1\",category:2,key:\"sample-key-3\",value:\"hello venus!\"},\n    {type:\"complex\",module:\"1\",category:2,key:\"sample-key-4\",value:\"hello sun!\"}\n]\n\nconst formatter = new fjs.ArrayFormatter(null,true,\n    new fjs.ObjectSwitchFormatter(null,[\n        {key:\"type\",value:\"simple\",formatter:new fjs.ObjectFormatter(null,false,[\n            new fjs.PropertyFormatter(\"key\"),\n            new fjs.PropertyFormatter(\"value\")\n        ])},\n        {key:\"type\",value:\"complex\",formatter:new fjs.ObjectFormatter(null,true,[\n            new fjs.PropertyFormatter(\"module\"),\n            new fjs.PropertyFormatter(\"category\"),\n            new fjs.PropertyFormatter(\"key\"),\n            new fjs.PropertyFormatter(\"value\")\n        ])},\n    ])\n)\n```\n**Expected Output:**\n```json\n[\n    {\"key\":\"sample-key-1\",\"value\":\"hello world!\"},\n    {\"key\":\"sample-key-2\",\"value\":\"hello mars!\"},\n    {\n        \"module\":\"1\",\n        \"category\":2,\n        \"key\":\"sample-key-3\",\n        \"value\":\"hello venus!\"\n    },\n    {\n        \"module\":\"1\",\n        \"category\":2,\n        \"key\":\"sample-key-4\",\n        \"value\":\"hello sun!\"\n    }\n]\n```\n\n### Example 4: Using The Default Formatter\n\u003e There will be some cases where you don't know the value/contents of a variable.\n\u003e This isn't that helpful when you need to know the entire structure of the JSON.\n\u003e\n\u003e Luckly there is a solution: Using the `DefaultFormatter`! It's just a wrapper around the default `JSON.stringify()`!\n\n```js\nconst input = {\n    property1:\"this is the first property\",\n    property2:\"this is the second property\",\n    property3:123,\n    subObject:{\n        sub_property_1:true,\n        sub_property_2:false,\n        sub_array:[\"abcd\",\"efg\",\"hijk\",\"lmnop\",\"qrst\",\"uvw\",\"xyz\",\"and thats the alphabet!\"]\n    }\n}\n\nconst formatter = new fjs.ObjectFormatter(null,true,[\n    new fjs.PropertyFormatter(\"property1\"),\n    new fjs.PropertyFormatter(\"property2\"),\n    new fjs.PropertyFormatter(\"property3\"),\n    new fjs.TextFormatter(),\n    \n    //we don't know the contents of this object\n    //but we still want to render it multiline/inline\n    new fjs.DefaultFormatter(\"subObject\",true)\n```\n**Expected Output:**\n\u003e You will automatically see that not only the object got rendered `multiline`, but the entire part including the array got rendered `multiline`!\n\n```json\n{\n    \"property1\":\"this is the first property\",\n    \"property2\":\"this is the second property\",\n    \"property3\":123,\n    \n    \"subObject\":{\n        \"sub_property_1\": true,\n        \"sub_property_2\": false,\n        \"sub_array\": [\n            \"abcd\",\n            \"efg\",\n            \"hijk\",\n            \"lmnop\",\n            \"qrst\",\n            \"uvw\",\n            \"xyz\",\n            \"and thats the alphabet!\"\n        ]\n    }\n}\n```\n\n## ❤️ Sponsors\nWe don't have any sponsors yet! Would you like to do it?\n\n## 🛠️ Contributors\n|Role               |User (Discord/Github)|\n|-------------------|-------------------|\n|🖥️ Main Developer   |djj123dj           |\n\n## ⭐️ Star History\nPlease help us grow by giving a star! It would help us a lot!\n\n\u003ca href=\"https://star-history.com/#DJj123dj/formatted-json-stringify\u0026Date\"\u003e\n \u003cpicture\u003e\n   \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://api.star-history.com/svg?repos=DJj123dj/formatted-json-stringify\u0026type=Date\u0026theme=dark\" /\u003e\n   \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://api.star-history.com/svg?repos=DJj123dj/formatted-json-stringify\u0026type=Date\" /\u003e\n   \u003cimg alt=\"Star History Chart\" src=\"https://api.star-history.com/svg?repos=DJj123dj/formatted-json-stringify\u0026type=Date\" /\u003e\n \u003c/picture\u003e\n\u003c/a\u003e\n\n## 📎 Links\ncurrent version: _v1.3.1_\n\u003c/br\u003echangelog: [click here](https://www.github.com/DJj123dj/formatted-json-stringify/releases)\n\u003c/br\u003esupport: [click here](https://discord.dj-dj.be/)\n\n© 2026 - DJdj Development | [Website](https://www.dj-dj.be) | [Support Server](https://discord.dj-dj.be) | [Terms Of Service](https://www.dj-dj.be/terms)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjj123dj%2Fformatted-json-stringify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjj123dj%2Fformatted-json-stringify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjj123dj%2Fformatted-json-stringify/lists"}