If your JSON doesn't parse, actually examining the generated JSON and figuring out why it doesn't parse is probably the way to go.
Of course, by hand-rolling your JSON you are trying to re-invent the wheel. Why not just build the Perl structure and then have something like the JSON module do the heavy lifting for you?
OK, JSON is not a core module, and maybe you are one of those unfortunates who can not install the module of your choice where you need it. You might still use the JSON module to help validate your hand-generated (yukkk!) JSON.