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": "Norris Schmeler",
"b": "Arvilla Pacocha"
},
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": {
"a": "Tad Jenkins",
"b": "Monet Cruickshank"
},
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": {
"b": "Fredricka Walker"
},
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": {
"a": "Ines Okuneva DDS",
"b": "Buford Zulauf"
},
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": {
"b": "Santina Beier"
},
"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": true
},
{
"b": false
},
{
"b": true
},
{
"b": true
},
{
"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": true
}
]

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"
]
}
]
}
}
}