Docs
array

array

In order to generate an array, you can use the array generator. This generator has two modes: random and fixed.

Random mode

In this mode, the generator will generate an array with either a random or fixed length. The items inside the array will be generated using the items schema. The generator has the following parameters:

  • length: The length of the array, which is either a fixed or random value
  • items: The schema of the items inside the array

Defining the number of items generated

The length parameter is an object containing either a fixed value or a lower and upper length limit to generate a random length between those two values.

Fixed length

Generate an array with a fixed length of 10 elements:

{
  "type": "array",
  "length": {
    "value": 10
  }
}

or

{
  "type": "array",
  "length": 10
}

Random length

Generate an array with a random length between 5 and 10 elements:

{
  "type": "array",
  "length": {
    "min": 5,
    "max": 10
  }
}

Fixed mode

In this mode, the generator will generate an array from a fixed list of values. The generator has the following parameters:

  • values: The list of values to generate the array from

Examples

Generate an array of strings

Generate an array full of strings with a random length:

{
  "type": "array",
  "length": {
    "min": 0,
    "max": 10
  },
  "items": {
    "type": "string",
    "value": "test"
  }
}

Generate an array with fixed values

{
  "type": "array",
  "values": [
    "test",
    "test2",
    {
      "type": "number",
      "precision": 2
    }
  ]
}

Generate an array with fixed values and random values

You can use the flatten generator in order to combine the values of the array generators in order to generate an array with both fixed and random values:

{
  "type": "flatten",
  "values": [
    {
      "type": "array",
      "values": [
        "test",
        "test2"
      ]
    },
    {
      "type": "array",
      "length": {
        "min": 0,
        "max": 5
      },
      "items": {
        "type": "string",
        "generator": {
          "type": "fullName"
        }
      }
    }
  ]
}