Hey !
I'm making a Node.js extension, and I would like to return a json format object, instead of a json-formatted string.
#include <node.h>
#include <node_object_wrap.h>
using namespace v8;
void ListDevices(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
std::string json = "[\"test\", \"test2\"]";
args.GetReturnValue().Set(String::NewFromUtf8(isolate, json.c_str()));
}
void InitAll(Handle<Object> exports) {
NODE_SET_METHOD(exports, "listDevices", ListDevices);
}
NODE_MODULE(addon, InitAll)
How can it be done ?
var addon = require("./ADDON");
var jsonvar = JSON.parse(addon.listDevices());
console.log(jsonvar);
Actually, in this part, I would like to remove the JSON.parse
By the way, is it me, or it is really difficult to find documentation ? I tried on google, but a lot of content was out of date, and in v8.h, interesting functions weren't documented.
Thank you ;)