Fixed JSON cleanup code