# JSON Mask (JsonMaskGenerator)

The [JSON Mask](https://docs.tonic.ai/app/generation/generators/generator-reference/json-mask) generator runs a selected generator on values that match a specified JSONPath.

## Link object structure <a href="#generator-api-json-mask-link-object" id="generator-api-json-mask-link-object"></a>

For the JSON Mask generator, you provide a link object for each sub-generator configuration.

The generator does not itself support consistency or differential privacy.

The `metadata` object is populated from the [`JsonMaskMetadata`](https://app.tonic.ai/apidocs/index.html#/models/JsonMaskMetadata) object, and includes:

* `pathExpression`, which is the JSONPath that identifies the value to apply the sub-generator to.
* The types of values to apply the sub-generator to.
* The `subGeneratorMetadata` object, which identifies and configures the sub-generator.

Here is the basic structure of a link object for a JSON Mask sub-generator.

{% code overflow="wrap" %}

```json
{
  "schema": "string",
  "table": "string",
  "column": "string",
  "metadata": {
    "generatorId": "JsonMaskGenerator",
    "customValueProcessor": "string",  //If custom value processor applied  
    "pathExpression": "string",
    "jsonFilterTypes": [ enum ], 
    "subGeneratorMetadata": {
      "generatorId": "string",
      "presetId": "string",
      //Metadata for the selected sub-generator
      "customValueProcessor": "string"  //If custom value processor applied to the sub-generator
    }
  }
}
```

{% endcode %}

## Example replacement <a href="#generator-api-json-mask-replacement" id="generator-api-json-mask-replacement"></a>

In the following example replacement for the JSON Mask generator:

* The Date Truncation generator is applied to all values of the JSONPath expression `$[*].start`. The value is truncated to the year, and the birthdate flag is off.
* The Email generator is applied to all values of the JSONPath expression `$[0].email`. The generated email addresses all use gmail.com as the domain, and no domains are excluded. Invalid email addresses are replaced. Consistency is disabled.
* If there is an error applying those generators, then the fallback generator is the Null generator.

```json
{
  "name": "json_data",
  "schema": "public"
  "table": "big_json",
  "links": [
    {
      "schema": "public",
      "table": "big_json",
      "column": "json_data",
      "metadata": {
        "generatorId": "JsonMaskGenerator",
        "presetId": "JsonMaskGenerator",
        "pathExpression": "$[*].start",
        "jsonFilterTypes": [
          0
        ],
        "subGeneratorMetadata": {
          "presetId": "DateTruncationGenerator",
          "generatorId": "DateTruncationGenerator",
          "datePart": "Year",
          "isBirthDate": false
        }
      }
    },
    {
      "schema": "public",
      "table": "big_json",
      "column": "json_data",
      "metadata": {
        "generatorId": "JsonMaskGenerator",
        "presetId": "JsonMaskGenerator",
        "pathExpression": "$[0].email",
        "jsonFilterTypes": [
          0
        ],
        "subGeneratorMetadata": {
          "presetId": "EmailGenerator",
          "generatorId": "EmailGenerator",
          "domain": "gmail.com",
          "excludedDomain": "",
          "replaceInvalidEmails": true,
          "isConsistent": false
        }
      }
    }
  ],
  "fallbackLinks": [
    {
      "schema": "public",
      "table": "big_json",
      "column": "json_data",
      "metadata": {
        "generatorId": "NullGenerator"
      }
    }
  ]
} 
```
