You can find some experimental support for JSON in my fork of the core
CFEngine here:

https://github.com/tzz/core/tree/feature/json

This is rough undocumented code intended as a proof of concept, written
in my spare time.  It's not officially supported by CFEngine!

It provides three things (the path is an array like ["x", 0] to denote
key "x" and array index 0):

1)

"varname" string => readjsonstring("JSON data", "JSON path", maxlength);

2) 

# returns array values or object elements
"listvar" slist => readjsonslist("JSON data", "JSON path", maxitems);

# return array indices or object keys
"listvar" slist => readjsonkeys("JSON data", "JSON path", maxitems);

3) various booleans that return a class, all taking ("JSON data", "JSON
path") parameters:

isjsonexists
isjsonfalse
isjsontrue
isjsonprimitive
isjsoncontainer
isjsonarray
isjsonobject

There are acceptance tests in
tests/acceptance/01_vars/02_functions/08[1-3].cf which show the usage of
these functions clearly.

I need your comments please:

- is this something you've been looking for?

- should I consolidate the booleans into a single function that takes a
  string parameter to denote the test?

- do the functions work like you'd expect?  How would you change them?

I look forward to your comments!

Ted
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to