https://github.com/kikobeats/json-future
Modern JSON interface.
https://github.com/kikobeats/json-future
Last synced: 19 days ago
JSON representation
Modern JSON interface.
- Host: GitHub
- URL: https://github.com/kikobeats/json-future
- Owner: Kikobeats
- License: mit
- Created: 2015-10-16T15:13:09.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-07-28T08:10:31.000Z (9 months ago)
- Last Synced: 2025-04-10T01:16:00.621Z (19 days ago)
- Language: JavaScript
- Homepage: https://nicedoc.io/kikobeats/json-future
- Size: 204 KB
- Stars: 56
- Watchers: 5
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# JSON Future
![]()

[](https://travis-ci.org/Kikobeats/json-future)
[](https://www.npmjs.org/package/json-future)> Modern JSON interface. [propositions for ECMAScript 7](https://github.com/mohsen1/async-json).
## Why
* High level methods for manipulate JSON files.
* Backward compatibility with JSON Object in Node/Browser.
* Async support (callback/promise) based on [ECMAScript proposal](https://github.com/mohsen1/async-json).JSON Future is based into a set of cool libraries to handle JSON, but some of this libraries uses promises or callback style. This library adds an extra layer to call these libraries uniformly.
## Install
```bash
npm install json-future --save
```## Usage
```js
const jsonFuture = require('json-future')
```Don't be afraid to replace for the default `JSON` object. The library is specially designed for be compatible and don't break your code:
```js
JSON = require('json-future')
```Also you can do this action using the `register` helper:
```js
require('json-future/register')
```## API
In `async` methods, if you don't provide a callback for node style, then the method return a `Promise`.
### .stringify(input, [replacer], [space])
### .stringifyAsync(input, [replacer], [space], [cb])Creates the `string` version of the input.
### .parse(input, [reviver], [filename])
### .parseAsync(input, [reviver], [filename], [cb])Creates the `object` version of the input.
### .load(filepath)
### .loadAsync(filepath, [cb])Returns the parsed JSON.
### .save(filepath, data, [options])
### .saveAsync(filepath, data, [options], [cb])Stringify and write JSON to a file atomically.
#### options
##### indent
Type: `string`, `number`
Default: `\t`Indentation as a string or number of spaces.
Pass in `null` for no formatting.##### sortKeys
Type: `boolean`, `function`
Default: `false`Sort the keys recursively.
Optionally pass in a [`compare`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) function.##### replacer
Type: `function`
Passed into [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter).
##### mode
Type: `number`
Default `438` *(0666 in octal)*[Mode](https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation) used when writing the file.
## License
MIT © [Kiko Beats](http://kikobeats.com)