replaced json_encode with recursive array/object-literal encoding

I encountered a problem with json_encode in that it cannot echo object literals or raw expressions (eg, functions or variable names).

This will recursively create object literals or arrays as necessary.