Redmine#6008: writejson() function

for https://dev.cfengine.com/issues/6008

brought up by @neilhwatson and many others...  pretty trivial code!  But it doesn't check that the file write succeeded, please suggest if that needs work.

Documentation to be provided upon merge as usual.