Using custom Javascript function to extract values from JSON string


I have created a Javascript function “new.js” which I am trying to use to extract a list of device values from the .things file and return the values to the terminal console. When I run the function node new.js “GetJsonValue()” I get “transform is not defined”. I am not sure what I am doing wrong here…

Here is my JS function:

function GetJsonValue(){
var fs = require(“fs”)
var text = fs.readFileSync("./org.eclipse.smarthome.core.thing.Thing.json").toString()
var result = transform(“JSONPATH”, “$.device”, text)
return result

I am not sure I am going about this in the right way…help please!

I don’t think you can easily call the OH transformation service from some javascript.

That’s okay, javascript can handle JSON by itself, example

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.