Added extra check for json-encoding of the data.