You can use json_generater to build json  conveniently.