Skip to main content
1-Visitor
November 30, 2017
Question

How do I create and write a JSON file to a repo containing thing properties

  • November 30, 2017
  • 1 reply
  • 3743 views

Hello,

I have a thing. I have a set of properties in that thing

property1, property2.

The aim is to create a JSON file containing these two properties and send these to a remote edge via the file repository transfer service. The edge is running EMS. There are a lot more properties, but this is an example.

There are two parts to this question:

1. How do I write these properties to a JSON file. The only way to convert to JSON is via an INFOTABLE, but this is not a table, just a static config file.

2. Once I convert to JSON, what is the procedure to save to a particular repo. I see SaveJSON.

1 reply

17-Peridot
November 30, 2017

Your service will look something like this:

var content = {

    "param1" : "value1",

    "param2" : "value2"

};

var params = {

path: "/Test/myNewJSONfile.json" /* STRING */,

content: content /* JSON */

};

me.SaveJSON(params);

For "path", just replace the string with the path in your file repository and include your new file name.

gseq1-VisitorAuthor
1-Visitor
November 30, 2017

Thank you, almost there.

I was able to create the file with JSON content.

Instead of hard coding those parameters under content, is there a way to use the thing as an input to content? I tried doing that, but the JSON is empty.

17-Peridot
November 30, 2017

What do you want your JSON to contain?  You could create a service that outputs a JSON and use that as well.  Or, if you are trying to create a JSON from a string, you can use parse functions to create a JSON from that.