[HowTo] Understanding, viewing and editing JSON files

Tips, Tricks and Scripts to enhance your home automation and workaround known device bugs, limitations and incompatibilities
Post Reply
User avatar
kambis
Posts: 36
Joined: 23 Jun 2014 08:06
Location: Germany
Contact:

[HowTo] Understanding, viewing and editing JSON files

Post by kambis » 30 Jun 2014 03:01

as part of my studies on Z-Way programming and debugging, I was faced to read and understand JSON files within the home automation Module and userModule folders.

Google searches resulted into several tools especially online ones for handling JSON files. But one local editing tool was in my case the winner and helped me to easily work with JSON files. This info might be interesting for others in this forum:

A small easy windows EXE file called JSONedit seems to be a good helper. here the link to the site: http://tomeko.net/software/JSONedit/. At the end of page you can download the latest version 0.9.8 (as per 30.06.2014) and have a look at it. Also the data on the site http://www.json.org/ was very helpful for me.

Now if Z-Way developers would provide some data about implemented JSON features in the Z-Way-Server, then one could modify and generate much more easier JSON files for home automation modules.
:roll:

pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Understanding, viewing and editing JSON files

Post by pofs » 30 Jun 2014 05:21

Which "JSON features" are you talking about?

State files under /automation/storage can be loaded with:

Code: Select all

var obj = loadObject("name");
After that obj will be just a JS object containing values from JSON file.
You may add, remove or modify properties of obj and its child objects.

Code: Select all

obj.a = 1;
obj.b = {};
obj.b.c = 2;
delete obj.a;
Object can be saved with:

Code: Select all

saveObject("name",obj);
As folder name suggests, it is a storage for module data, it shouldn't be edited by user. File names are derived from object names and can't be easily guessed.

You can also load objects from arbitrary JSON file with:

Code: Select all

var obj = loadJSON("path");
The only difference from loadObject() is that you can specify file path instead of object name.
loadJSON() is more suitable for config files readable and editable by human.

Also there are built-in JSON.stringify() and JSON.parse() functions.

User avatar
kambis
Posts: 36
Joined: 23 Jun 2014 08:06
Location: Germany
Contact:

Understanding module.json files

Post by kambis » 30 Jun 2014 09:25

Thank you pofs.
The features I'm asking are about keywords possible for module.json files mentioned in the latest Z-Way Developers Documentation, version 1.7 ( http://razberry.z-wave.me/docs/zwayDev.pdf ) on page 49. The few lines there explaining about autoload, singleton, defaults, actions and metrics are not reflecting all the keywords I'm finding in several module.json files in the automation/modules/* subfolders.

You find there key words like: options, schema, required, lable, helper, user view, title, description, field, type and many many other keywords beside the metadata within the files.

My question is if there is any kind reference data how to compose those files or
understand how they are built.

User avatar
PoltoS
Posts: 4136
Joined: 26 Jan 2011 19:36

Re: Understanding, viewing and editing JSON files

Post by PoltoS » 08 Jul 2014 11:00

Indeed, options and schema are not really documented. Here we use third part AlpacaJS project. The only extension we have made is namespaces:... stuff to load data from dictionaries. These are quite obvious. Other things are documented in AlpacaJS project. I would suggest to look on examples in modules and copy them.

User avatar
kambis
Posts: 36
Joined: 23 Jun 2014 08:06
Location: Germany
Contact:

Reference documentation for module.json files

Post by kambis » 08 Jul 2014 16:54

PoltoS,
based on your information I found the link:
http://www.alpacajs.org/examples/compon ... field.html

which explains in detail many of my questions and I see in addition modifications beyond namespaces:... stuff.
For example you use the keyword defaults {...} instead the keyword data {...} or you define in your document Z-Way Developers Documentation, version 1.7 ( http://razberry.z-wave.me/docs/zwayDev.pdf ) on page 49 additional keywords like actions and metrics.

I was also not able to play around with the "VIEW_WEB_EDIT", "VIEW_WEB_EDIT_LIST", "VIEW_WEB_EDIT_TABLE" options in the layout.

Do you have any additional data, which you can provide about namespaces,
layout options or other modifications :?:

User avatar
PoltoS
Posts: 4136
Joined: 26 Jan 2011 19:36

Re: Understanding, viewing and editing JSON files

Post by PoltoS » 08 Jul 2014 22:06

We never used layouts. not even tested them.

Indeed, defaults is additional stuff from us - we use it to initialize data if empty. But note that data is read from config.json file in storage/ and is filled automatically.

As for namespaces, there is a field saying that data will come from a namespace. Then after : goes the name of the namespace and then after another : the key to be used (in optionLabels we use deviceName, in schema - deviceId)

User avatar
kambis
Posts: 36
Joined: 23 Jun 2014 08:06
Location: Germany
Contact:

Example code for module.json file

Post by kambis » 13 Jul 2014 20:44

After studying the information given on
http://www.alpacajs.org/examples/compon ... field.html
I could manage to create my own module.json file for my first automation userModule.

More data is available in this post:
viewtopic.php?f=3424&t=20528

Post Reply