https://github.com/bconnorwhite/stringify-json-object
Stringify and format a JSON object.
https://github.com/bconnorwhite/stringify-json-object
json node nodejs stringify typescript
Last synced: about 1 month ago
JSON representation
Stringify and format a JSON object.
- Host: GitHub
- URL: https://github.com/bconnorwhite/stringify-json-object
- Owner: bconnorwhite
- Created: 2020-08-28T03:06:06.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2023-01-24T18:27:08.000Z (over 3 years ago)
- Last Synced: 2025-03-02T11:20:06.882Z (over 1 year ago)
- Topics: json, node, nodejs, stringify, typescript
- Language: TypeScript
- Homepage:
- Size: 324 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
Stringify and format a JSON object.
_If I should maintain this repo, please ⭐️_
_DM me on [Twitter](https://twitter.com/bconnorwhite) if you have questions or suggestions._
---
## Installation
```sh
yarn add stringify-json-object
```
```sh
npm install stringify-json-object
```
```sh
pnpm add stringify-json-object
```
## Usage
The `stringify` function works like `JSON.stringify`:
```ts
import stringify from "stringify-json-object";
stringify(true); // 'true'
stringify(1); // '1'
stringify("foo"); // '"foo"'
stringify({ foo: "bar" }); // '{"foo":"bar"}'
stringify({ foo: "bar", missing: undefined }); // '{"foo":"bar"}'
```
The `stringify` function also accepts an options argument, to easily format the output:
```ts
import stringify from "stringify-json-object";
stringify({ foo: "bar" }, { pretty: true }); // '{\n "foo": "bar"\n}"
```
Additionally, primitives resolve to typed string literals:
```ts
import stringify from "stringify-json-object";
stringify(true); // "true"
stringify(1); // "1"
stringify("foo"); // "\"foo\""
stringify({ foo: "bar" }); // string
```
Dependencies
- [types-json](https://www.npmjs.com/package/types-json): Type checking for JSON values
Dev Dependencies
- [autorepo](https://www.npmjs.com/package/autorepo): Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.
License
[MIT](https://opensource.org/licenses/MIT)
## Related Packages
- [parse-json-object](https://www.npmjs.com/package/parse-json-object): Parse a typed JSON object