Validating JSON Data - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

JSON data is automatically validated by default. You can use the SET SESSION JSON IGNORE ERRORS attribute to disable validation if the data is from a reliable source and is accurate. Disabling validation may improve performance.

To disable validation for the current session, use the following statement:

SET SESSION JSON IGNORE ERRORS ON;

To re-enable validation for the current session, use the following statement:

SET SESSION JSON IGNORE ERRORS OFF;
If JSON validation is disabled at either the session or system level, the following occur:
  • Even with validation disabled, JSON text imported to the database and stored as JSON text is minimally validated to make sure that the opening and closing braces and brackets of the JSON document properly match. For example, '{' matches with '}' and '[' matches with ']'. Failure to pass this minimal validation is an error.
  • JSON text imported to the database and stored as one of the binary storage formats is still validated. Vantage does not allow an improper JSON document to be converted to one of the binary storage formats. The setting for the JSON IGNORE ERRORS session attribute has no impact.
  • The maximum length specified for a JSON column that uses a binary storage format must cover the length of the data in its binary format. If validation is disabled and the binary data inserted exceeds the defined length of the column, an error is reported.

    If the binary data inserted fits within the defined length of the column, but the serialized (text) format exceeds the length, an error is reported when trying to access the data as text.

  • JSON data imported to the database in its BSON format and stored in the BSON format is accepted without any validation. Because validation is completely disabled, no errors are reported for any issues encountered.
  • JSON data cannot be imported to the database in UBJSON format. Therefore, the UBJSON data is validated when converted from its source format because Vantage cannot convert invalid data.
BSON is the default document storage scheme for MongoDB. There are additional restrictions that dictate whether BSON data is valid in MongoDB. These restrictions are as follows:
  • A user document element name cannot begin with a '$' character.
  • A user document element name cannot have a '.' character in the name.
  • The element name _id is reserved for use as a primary key id, but you can store anything that is unique in that field.

Even with validation enabled, this level of validation needed for MongoDB is not performed when inserting data into a JSON column which stores its data as BSON. However, the AsBSON method provides an optional parameter that allows you to perform this strict validation.

You can use the BSON_CHECK function to verify that JSON data in BSON format is compliant with BSON syntax. If the data is valid, the BSON_CHECK function returns OK. The BSON_CHECK function also has an optional parameter that allows you to specify whether to perform a strict validation which verifies that the BSON syntax is valid for MongoDB.

You can use the JSON_CHECK function to verify that a JSON string is compliant with JSON syntax. If the JSON string is valid, the JSON_CHECK function returns OK.