An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          


stringify-json-object



NPM


TypeScript


Coverage Status


Stringify and format a JSON object.


_If I should maintain this repo, please ⭐️_

GitHub stars

_DM me on [Twitter](https://twitter.com/bconnorwhite) if you have questions or suggestions._

Twitter

---

## 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

```


Dependenciesdependencies

- [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 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