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": "Brady Dare",
"b": "Estella Schiller"
},
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": {
"b": "Ms. Lois McGlynn"
},
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": {
"a": "Dania Predovic",
"b": "Verdie Erdman II"
},
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": {
"b": "Raguel DuBuque"
},
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": {
"a": "Avery Conn",
"b": "Rodger Fritsch"
},
"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": false
},
{
"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": true
},
{
"a": true
},
{
"a": true
},
{
"a": false
},
{
"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"
]
}
]
}
}
}