Working with json files

I’m a running a simple web server

Works great but I am having difficulties read in the data into openhab

The web output looks like this

[{“relay_port”: 4, “x_port”: 0}]

I need 2 x items displaying 1 integer each. The help file say that the output is a json file.

I just want the Intergers displayed.

Sounds terrible but I need help if anyone can spare the time.

Kind regards

You will need to use a transform, and then you can assign them to an item.

create the transform/relay_port.js file with the below content.


Then reference it in your items file.

Number RelayPort "" { http="<[]" }

Then repeat for the second value. Each transform is in it’s own file.

Thank you so much for taking the time to respond. I have followed your post, but I am only reading a “-” when displaying the item.

Just to recap

  1. created the json file in /opt/openhab/configurations/transform.
  2. relay_port.js with line 1 line only


  1. created item

Number RelayPort "" { http="<[]" }

  1. sitemap entry

Text item=RelayPort label="Relay Port [%d]"

BTW the web server in am using is

It is awesome!

Kind Regards

Hi Jason,
hope you waited some time for getting the item updated? the 6000 is the refreshrate in miliseconds.

Start - before getting the item into a Number putting this one into a string item istead to see what the transform gets back at all.

String RelayPort “RelayPort [%s]” { http="<[]" }

In addition it seems that the item type definition is missing in your number item:
Number RelayPort “RelayPort [%d]” { http="<[]" }


Hi Karsten,

Thank you, it did update the type definition as suggested. I also updated the time to 2000 ms. Also change the item names.

The int is displaying “-”
and the String is displaying a “null”

Screen shot of log.

I did manage to get it working with a REGEX, but it seems that it is not the best practice.

Once again, thanks for all the help.

Kind Regards

I’m no json expert, but I am wondering if it is the square brackets causing the parser to not find the path.

Can you have the webserver return {“relay_port”: 4, “x_port”: 0} instead?

Hi, sorry for the late response. It does seem to be an issue with the [ ]'s

I will have a look and see if I can modify the code to exclude the [ ]'s.

Once again, thank you so much for the assistance and patients.

Kind Regards

Have you tried jsonpath instead?