json: fix mem leak and compiler warnings