Improved clearJson function