https://github.com/mkrufky/node-native-json
Access the v8::JSON object methods Parse & Stringify from native c++ addons across all versions of node.js
https://github.com/mkrufky/node-native-json
Last synced: 4 months ago
JSON representation
Access the v8::JSON object methods Parse & Stringify from native c++ addons across all versions of node.js
- Host: GitHub
- URL: https://github.com/mkrufky/node-native-json
- Owner: mkrufky
- License: mit
- Created: 2017-03-11T23:30:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-13T20:55:36.000Z (over 8 years ago)
- Last Synced: 2025-06-03T02:24:15.010Z (4 months ago)
- Language: C++
- Homepage:
- Size: 101 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
This project has been merged into `NAN` and is now deprecated. Use `Nan::JSON` from `NAN` v2.6.2 or later. See [Nan::JSON](https://github.com/nodejs/nan/blob/master/doc/json.md)
# native-json
Access the `v8::JSON` object methods `Parse` & `Stringify` from native c++ addons across all versions of node.js
[](https://nodei.co/npm/native-json/)
[](http://travis-ci.org/mkrufky/node-native-json)
[](https://ci.appveyor.com/project/mkrufky/node-native-json)native-json is a header package for building c++ native addons for node.js that is meant to complement **[nan](https://github.com/nodejs/nan)** by adding an interface to the `v8::JSON` object's `Parse` and `Stringify` methods that can be relied upon regardless of the version of node.js that the addon is being built against.
## Usage
Simply add **nan** and **native-json** as dependencies in the *package.json* of your Node addon:
``` bash
$ npm install --save nan
$ npm install --save native-json
```Pull in the paths to **nan** and **native-json** in your *binding.gyp* so that you can use `#include ` in your *.cpp* files:
``` python
"include_dirs" : [
"` when compiling your addon.## API
``` c++
Nan::MaybeLocal Parse(v8::Local jsonString);Nan::MaybeLocal Stringify(v8::Local jsonObject);
Nan::MaybeLocal Stringify(v8::Local jsonObject, v8::Local gap);
```To access the javascript function `JSON.parse()` from your c++ code, call `Native::JSON::Parse()` where you would normally call `v8::JSON::Parse()`, which would otherwise not be available in versions of node.js older than 0.12.x
``` c++
v8::Local jsonString =
Nan::New("{ \"JSON\": \"object\" }").ToLocalChecked();v8::Local parsedValue =
Native::JSON::Parse(jsonString).ToLocalChecked();
```To access the javascript function `JSON.stringify()` from your c++ code, call `Native::JSON::Stringify()` where you would normally call `v8::JSON::Stringify()`, which would otherwise not be available in versions of node.js older than 7.x
``` c++
v8::Local object = Nan::To(parsedValue);v8::Local stringified =
Native::JSON::Stringify(object).ToLocalChecked();
```### Tests
To run the native-json tests do:
``` sh
npm install
npm run-script rebuild-tests
npm test
```Or just:
``` sh
npm install
make test
```## Licence & copyright
Copyright (c) 2017 Michael Ira Krufky
native-json is licensed under an MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.