Skip to main content

Function modifiers

elide

Commentary

added in 0.1.21

How frequently this generator call should be skipped, and its position in the resulting data structure erased.

The frequency can be chosen with a rate 1, presence of a value 2, or absence of a value 3. Only one can be used, so if multiple strategies are specified, they are selected in the order written here.


Examples

Eliding with a rate

Specify rate to elide a percentage of values. In this example, 50% of the values are elided.

{
"a": {
"_gen": "string",
"expr": "#{Name.fullName}",
"elide": {
"rate": 0.5
}
},
"b": {
"_gen": "string",
"expr": "#{Name.fullName}"
}
}
[
{
"topic": "sandbox",
"key": null,
"value": {
"a": "Twanda Block",
"b": "Dr. Madalene Beier"
},
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": {
"a": "Scarlett Klein",
"b": "Dr. Candra McCullough"
},
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": {
"b": "Fawn Reynolds"
},
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": {
"a": "Mrs. Percy Cronin",
"b": "Tony West"
},
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": {
"b": "Rolland Turcotte"
},
"headers": null
}
]

Eliding with presence

Specify whenPresent to elide when a reference value is non-null.

{
"topic": "sandbox",
"vars": {
"someMap": {
"someKey": 42
}
},
"value": {
"a": {
"_gen": "boolean",
"elide": {
"whenPresent": {
"_gen": "var",
"var": "someMap",
"path": [
"someKey"
]
}
}
},
"b": {
"_gen": "boolean",
"elide": {
"whenPresent": {
"_gen": "var",
"var": "someMap",
"path": [
"missingKey"
]
}
}
}
}
}
[
{
"b": false
},
{
"b": true
},
{
"b": true
},
{
"b": false
},
{
"b": true
}
]

Eliding with absence

Specify whenAbsent to elide when a reference value is null.

{
"topic": "sandbox",
"vars": {
"someMap": {
"someKey": 42
}
},
"value": {
"a": {
"_gen": "boolean",
"elide": {
"whenAbsent": {
"_gen": "var",
"var": "someMap",
"path": [
"someKey"
]
}
}
},
"b": {
"_gen": "boolean",
"elide": {
"whenAbsent": {
"_gen": "var",
"var": "someMap",
"path": [
"missingKey"
]
}
}
}
}
}
[
{
"a": false
},
{
"a": true
},
{
"a": true
},
{
"a": true
},
{
"a": false
}
]

Specification

JSON schema

{
"type": "object",
"properties": {
"elide": {
"type": "object",
"properties": {
"rate": {
"oneOf": [
{
"type": "number",
"minimum": 0,
"maximum": 1
},
{
"type": "object",
"properties": {
"_gen": {
"type": "string"
}
},
"required": [
"_gen"
]
}
]
},
"whenPresent": {
"type": "object",
"properties": {
"_gen": {
"type": "string"
}
},
"required": [
"_gen"
]
},
"whenAbsent": {
"type": "object",
"properties": {
"_gen": {
"type": "string"
}
},
"required": [
"_gen"
]
}
},
"oneOf": [
{
"required": [
"rate"
]
},
{
"required": [
"whenPresent"
]
},
{
"required": [
"whenAbsent"
]
}
]
}
}
}