diff options
author | Minteck <contact@minteck.org> | 2022-02-25 18:08:27 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-02-25 18:08:27 +0100 |
commit | a5c417748112e9d88d9ca522561e338eb9ba9007 (patch) | |
tree | ddab6e854fe8b50942a397a0d9fd8330ad662a97 /node_modules/nan/doc/json.md | |
download | argon-cdn-a5c417748112e9d88d9ca522561e338eb9ba9007.tar.gz argon-cdn-a5c417748112e9d88d9ca522561e338eb9ba9007.tar.bz2 argon-cdn-a5c417748112e9d88d9ca522561e338eb9ba9007.zip |
Initial commit
Diffstat (limited to 'node_modules/nan/doc/json.md')
-rw-r--r-- | node_modules/nan/doc/json.md | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/node_modules/nan/doc/json.md b/node_modules/nan/doc/json.md new file mode 100644 index 0000000..55beb26 --- /dev/null +++ b/node_modules/nan/doc/json.md @@ -0,0 +1,62 @@ +## JSON + +The _JSON_ object provides the C++ versions of the methods offered by the `JSON` object in javascript. V8 exposes these methods via the `v8::JSON` object. + + - <a href="#api_nan_json_parse"><b><code>Nan::JSON.Parse</code></b></a> + - <a href="#api_nan_json_stringify"><b><code>Nan::JSON.Stringify</code></b></a> + +Refer to the V8 JSON object in the [V8 documentation](https://v8docs.nodesource.com/node-8.16/da/d6f/classv8_1_1_j_s_o_n.html) for more information about these methods and their arguments. + +<a name="api_nan_json_parse"></a> + +### Nan::JSON.Parse + +A simple wrapper around [`v8::JSON::Parse`](https://v8docs.nodesource.com/node-8.16/da/d6f/classv8_1_1_j_s_o_n.html#a936310d2540fb630ed37d3ee3ffe4504). + +Definition: + +```c++ +Nan::MaybeLocal<v8::Value> Nan::JSON::Parse(v8::Local<v8::String> json_string); +``` + +Use `JSON.Parse(json_string)` to parse a string into a `v8::Value`. + +Example: + +```c++ +v8::Local<v8::String> json_string = Nan::New("{ \"JSON\": \"object\" }").ToLocalChecked(); + +Nan::JSON NanJSON; +Nan::MaybeLocal<v8::Value> result = NanJSON.Parse(json_string); +if (!result.IsEmpty()) { + v8::Local<v8::Value> val = result.ToLocalChecked(); +} +``` + +<a name="api_nan_json_stringify"></a> + +### Nan::JSON.Stringify + +A simple wrapper around [`v8::JSON::Stringify`](https://v8docs.nodesource.com/node-8.16/da/d6f/classv8_1_1_j_s_o_n.html#a44b255c3531489ce43f6110209138860). + +Definition: + +```c++ +Nan::MaybeLocal<v8::String> Nan::JSON::Stringify(v8::Local<v8::Object> json_object, v8::Local<v8::String> gap = v8::Local<v8::String>()); +``` + +Use `JSON.Stringify(value)` to stringify a `v8::Object`. + +Example: + +```c++ +// using `v8::Local<v8::Value> val` from the `JSON::Parse` example +v8::Local<v8::Object> obj = Nan::To<v8::Object>(val).ToLocalChecked(); + +Nan::JSON NanJSON; +Nan::MaybeLocal<v8::String> result = NanJSON.Stringify(obj); +if (!result.IsEmpty()) { + v8::Local<v8::String> stringified = result.ToLocalChecked(); +} +``` + |