improve protection for JSON encoder for .json format and for Traces