Adding constraints to JSON attributes
About this task
To create and configure JSON attribute constraints:
Steps
-
Run
dsconfigwith thecreate-json-attribute-constraintsoption.Example:
In this example, a JSON attribute constraint is defined on the
appjsonattribute type. This constrains values of theappjsonattribute to be JSON objects. Becauseallow-unnamed-fieldsis set to false, those JSON objects can only have fields for which there is a corresponding JSON field constraints definition.appjsonis meant to be replaced by the name of the user’s desired attribute type, as defined in the directory schema. For more information, see About managing JSON attribute values.$ bin/dsconfig create-json-attribute-constraints \ --attribute-type appjson \ --set enabled:true \ --set allow-unnamed-fields:falseExample:
In this example, a JSON field constraint object is defined for the
email.verifiedfield. Theemail.verifiedfield must be present and must take a boolean value.$ bin/dsconfig create-json-field-constraints \ --attribute-type appjson \ --json-field email.verified \ --set value-type:boolean \ --set is-required:true \ --set index-values:false \ --set tokenize-values:false \ --set allow-null-value:trueExample:
In this example, a JSON field constraint object is defined for the
email.typefield. Theemail.typefield must be present and must take a value ofhome,work, orother.$ bin/dsconfig create-json-field-constraints \ --attribute-type appjson \ --json-field email.type \ --set value-type:string \ --set is-required:true \ --set index-values:false \ --set tokenize-values:true \ --set allowed-value:home \ --set allowed-value:other \ --set allowed-value:work \ --set allow-null-value:falseExample:
In this example, a JSON field constraint is defined for the
email.valuefield. Theemail.valuefield must be present and must take a string value that matches the specified regular expression.$ bin/dsconfig create-json-field-constraints \ --attribute-type appjson \ --json-field email.value \ --set value-type:string \ --set is-required:true \ --set index-values:true \ --set tokenize-values:false \ --set prime-index:true \ --set allow-null-value:true \ --set maximum-value-length:256 \ --set minimum-value-length:1 \ --set allowed-value-regular-expression:[-_\+\.\w\d]+@\w+\.\w{2,5}