https://github.com/tiaanduplessis/json
Nicer JSON parse and stringify
https://github.com/tiaanduplessis/json
json parse stringify wrapper
Last synced: about 1 month ago
JSON representation
Nicer JSON parse and stringify
- Host: GitHub
- URL: https://github.com/tiaanduplessis/json
- Owner: tiaanduplessis
- License: mit
- Created: 2017-07-15T22:15:43.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-06-12T21:44:13.000Z (about 6 years ago)
- Last Synced: 2025-08-17T19:14:15.213Z (10 months ago)
- Topics: json, parse, stringify, wrapper
- Language: JavaScript
- Size: 236 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @tiaanduplessis/json
[](https://npmjs.org/package/@tiaanduplessis/json)
[](https://npmjs.org/package/@tiaanduplessis/json)
[](https://github.com/RichardLitt/standard-readme)
[](https://npmjs.org/package/@tiaanduplessis/json)
[](http://makeapullrequest.com) [](https://github.com/feross/standard)
[](hhttps://travis-ci.org/tiaanduplessis/json)
[](https://greenkeeper.io/)
> Promisified & memoized [parse-json](https://www.npmjs.com/package/parse-json) & [fast-safe-stringify](https://github.com/davidmarkclements/fast-safe-stringify) bundled together
## Table of Contents
- [Install](#install)
- [Usage](#usage)
- [Contribute](#contribute)
- [License](#License)
## Install
This project uses [node](https://nodejs.org) and [npm](https://www.npmjs.com).
```sh
$ npm install @tiaanduplessis/json
$ # OR
$ yarn add @tiaanduplessis/json
```
## Usage
```js
import JSON from '@tiaanduplessis/json'
const obj = { foo: 5, baz: 5, bar: 7 }
const str = '{"foo": "5"}'
const badStr = '{foo: "5"}'
console.log(JSON.stringify(obj)) // "{"foo":5,"baz":5,"bar":7}"
JSON.parse(str).then(console.log).catch(error) // { foo: '5' }
JSON.parse(badStr).then(console.log).catch(console.error)
/*
{ JSONError: Unexpected token 'f' at 1:2
{foo: "5"}
^
at module.exports (/Users/Tiaan/Workspace/json/node_modules/parse-json/index.js:27:17)
at Object.parse (/Users/Tiaan/Workspace/json/src/index.js:13:22)
at Object. (/Users/Tiaan/Workspace/json/src/index.js:33:6)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16) name: 'JSONError' } undefined
*/
```
## Contribute
1. Fork it and create your feature branch: git checkout -b my-new-feature
2. Commit your changes: git commit -am 'Add some feature'
3. Push to the branch: git push origin my-new-feature
4. Submit a pull request
## License
MIT