Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

native-json

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

native-json

Access the v8::JSON object methods Parse & Stringify from native c++ addons across all versions of node.js

  • 2.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

This project has been merged into NAN and is now deprecated. Use Nan::JSON from NAN v2.6.2 or later. See Nan::JSON

native-json

Access the v8::JSON object methods Parse & Stringify from native c++ addons across all versions of node.js

NPM

Build Status Build status

native-json is a header package for building c++ native addons for node.js that is meant to complement 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:

$ 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 <native-json.h> in your .cpp files:

"include_dirs" : [
    "<!(node -e \"require('nan')\")",
    "<!(node -e \"require('native-json')\")"
]

This works like a -I<path-to-native-json> when compiling your addon.

API

Nan::MaybeLocal<v8::Value> Parse(v8::Local<v8::String> jsonString);

Nan::MaybeLocal<v8::String> Stringify(v8::Local<v8::Object> jsonObject);
Nan::MaybeLocal<v8::String> Stringify(v8::Local<v8::Object> jsonObject, v8::Local<v8::String> 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

v8::Local<v8::String> jsonString =
  Nan::New("{ \"JSON\": \"object\" }").ToLocalChecked();

v8::Local<v8::Value> 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

v8::Local<v8::Object> object = Nan::To<v8::Object>(parsedValue);

v8::Local<v8::String> stringified =
  Native::JSON::Stringify(object).ToLocalChecked();

Tests

To run the native-json tests do:

npm install
npm run-script rebuild-tests
npm test

Or just:

npm install
make test

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.

Keywords

FAQs

Package last updated on 13 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc