to_json function

to_json write data out as a JSON object