[aot] Re-organize JSON dumping code.