improved JSON validity check