Read variable from YML and JSON

Could we please get some built-in actions to read a variable from a YML or JSON file. The combination of string POS/SUBSTRING is tiresome and makes for an ugly project.

Thanks,
-Mike

JSON & YAML are on the todo for FB9, I’m open to suggestions on how this should work. One of the issues we have is that there isn’t an object variable type, so working with object graphs in variables currently isn’t possible. You can load the json (and perhaps the yaml) into a variable use the read file action, and then use a run script action (set to Javascript) to convert the string to an object :

[code]var obj = eval("(" + FBVariables.JSONFile + ‘)’); [/code]

Note that this is a potential security hole if you are not the generator of the json file (it could potentially contain malicious code).

One of the things we are looking at for FB9 is to replace the active scripting engine with a newer javascript engine (v8, chakracore or spidermonkey - still evaluating the best option) so that newer javascript features can be used. This would open up more options with regards to working with JSON/YAML.

Hi Vincent,

has there been any progress in that area? I face the same situation as Mike.

Regards
Martin

Unfortunately not. Replacing the scripting engine has proven very difficult, because so far none of the options support COM, which is required for interacting with things like office, wmi etc.

Something I did do some time back (10 months ago) was include json2.js with the install, so you can use it from script

//USEUNIT "%FBDIR%\Scripts\json2.js"
var json = '{"result":true, "count":42}';
obj = JSON.parse(json);

alert(obj.count);

I’ve used this myself but obviously we need a better option, and we’re still working towards a set of json oriented actions with jsonpath support (much like the xml actions).

Thanks Vincent.

Is there an option to write changes back into a json file. I need to update some values.

Martin

Ignore, got it.

Thanks
Martin