Best practices

Recommended practices for using json.Serializer to enhance performance and avoid common pitfalls.

The following best practices can help ensure effective use of json.Serializer:

  • Disable allowImplicitConversion in production to avoid silent errors.
  • Use native JSON booleans and numbers rather than quoted values (for example, use true instead of "true").
  • Favor strict formats for DATE (YYYY-MM-DD); for DATETIME and INTERVAL, you have options to use RFC 3339 and ISO 8601 standards, see json.Serializer options.
  • Use json_null attribute when handling NULL values. For more information about managing null with the json_null attribute, go to NULLs and empty structures.
  • Use the json_name attribute to map a BDL variable to a JSON element name that cannot be represented as a valid BDL identifier, such as names with spaces or special characters. For details, see Type attributes.