string

Synth's string generator type regroups many different useful functionalities, from the ability to generate sentences from a regular expression to dates and times, through leveraging Faker providers to generate valid addresses, telephone numbers, etc.

pattern#

String values generated by a specified regular expression in the pattern key.

Example#

{
"type": "string",
"pattern": "I am a (man|woman) with [2-9] friends"
}

uuid#

uuid generates hyphenated UUIDs.

This generator has no parameters.

Example#

{
"type": "string",
"uuid": {}
}

format#

format allows to format one or more string values by parsing a parametric format string and processing the specified replacements.

Example#

{
"type": "string",
"format": {
"format": "my name is {name} and my email is {email}",
"arguments": {
"name": {
"type": "string",
"faker": {
"generator": "username"
}
},
"email": {
"type": "string",
"faker": {
"generator": "safe_email"
}
}
}
}
}

faker#

Synth has an internal fake data generator that will generate fake data for semantic types such as Names, Addresses, etc.

Example#

{
"type": "string",
"faker": {
"generator": "address"
}
}

Faker offers a variety of different fake data, in different locales and can be leveraged easily from Synth schemas using the generator key.

first_name#

{
"type": "string",
"faker": {
"generator": "first_name"
}
}

last_name#

{
"type": "string",
"faker": {
"generator": "last_name"
}
}

title#

{
"type": "string",
"faker": {
"generator": "title"
}
}

suffix#

{
"type": "string",
"faker": {
"generator": "suffix"
}
}

name#

{
"type": "string",
"faker": {
"generator": "name"
}
}

name_with_title#

{
"type": "string",
"faker": {
"generator": "name_with_title"
}
}

credit_card#

{
"type": "string",
"faker": {
"generator": "credit_card"
}
}

free_email_provider#

{
"type": "string",
"faker": {
"generator": "free_email_provider"
}
}

domain_suffix#

{
"type": "string",
"faker": {
"generator": "domain_suffix"
}
}

free_email#

{
"type": "string",
"faker": {
"generator": "free_email"
}
}

safe_email#

{
"type": "string",
"faker": {
"generator": "safe_email"
}
}

username#

{
"type": "string",
"faker": {
"generator": "username"
}
}

ipv4#

{
"type": "string",
"faker": {
"generator": "ipv4"
}
}

ipv6#

{
"type": "string",
"faker": {
"generator": "ipv6"
}
}

ip#

{
"type": "string",
"faker": {
"generator": "ip"
}
}

mac_address#

{
"type": "string",
"faker": {
"generator": "mac_address"
}
}

color#

{
"type": "string",
"faker": {
"generator": "color"
}
}

user_agent#

{
"type": "string",
"faker": {
"generator": "user_agent"
}
}

rfc_status_code#

{
"type": "string",
"faker": {
"generator": "rfc_status_code"
}
}

valid_status_code#

{
"type": "string",
"faker": {
"generator": "valid_status_code"
}
}

company_suffix#

{
"type": "string",
"faker": {
"generator": "company_suffix"
}
}

company_name#

{
"type": "string",
"faker": {
"generator": "company_name"
}
}

buzzword#

{
"type": "string",
"faker": {
"generator": "buzzword"
}
}

buzzword_muddle#

{
"type": "string",
"faker": {
"generator": "buzzword_muddle"
}
}

buzzword_tail#

{
"type": "string",
"faker": {
"generator": "buzzword_tail"
}
}

catch_phrase#

{
"type": "string",
"faker": {
"generator": "catch_phrase"
}
}

bs_verb#

{
"type": "string",
"faker": {
"generator": "bs_verb"
}
}

bs_adj#

{
"type": "string",
"faker": {
"generator": "bs_adj"
}
}

bs_noun#

{
"type": "string",
"faker": {
"generator": "bs_noun"
}
}

bs#

{
"type": "string",
"faker": {
"generator": "bs"
}
}

profession#

{
"type": "string",
"faker": {
"generator": "profession"
}
}

industry#

{
"type": "string",
"faker": {
"generator": "industry"
}
}

city_prefix#

{
"type": "string",
"faker": {
"generator": "city_prefix"
}
}

city_suffix#

{
"type": "string",
"faker": {
"generator": "city_suffix"
}
}

city_name#

{
"type": "string",
"faker": {
"generator": "city_name"
}
}

country_name#

{
"type": "string",
"faker": {
"generator": "country_name"
}
}

country_code#

{
"type": "string",
"faker": {
"generator": "country_code"
}
}

street_suffix#

{
"type": "string",
"faker": {
"generator": "street_suffix"
}
}

street_name#

{
"type": "string",
"faker": {
"generator": "street_name"
}
}

time_zone#

{
"type": "string",
"faker": {
"generator": "time_zone"
}
}

state_name#

{
"type": "string",
"faker": {
"generator": "state_name"
}
}

state_abbr#

{
"type": "string",
"faker": {
"generator": "state_abbr"
}
}

secondary_address_type#

{
"type": "string",
"faker": {
"generator": "secondary_address_type"
}
}

secondary_address#

{
"type": "string",
"faker": {
"generator": "secondary_address"
}
}

zip_code#

{
"type": "string",
"faker": {
"generator": "zip_code"
}
}

post_code#

{
"type": "string",
"faker": {
"generator": "post_code"
}
}

building_number#

{
"type": "string",
"faker": {
"generator": "building_number"
}
}

latitude#

{
"type": "string",
"faker": {
"generator": "latitude"
}
}

longitude#

{
"type": "string",
"faker": {
"generator": "longitude"
}
}

phone_number#

{
"type": "string",
"faker": {
"generator": "phone_number"
}
}

cell_number#

{
"type": "string",
"faker": {
"generator": "cell_number"
}
}

file_path#

{
"type": "string",
"faker": {
"generator": "file_path"
}
}

file_name#

{
"type": "string",
"faker": {
"generator": "file_name"
}
}

file_extension#

{
"type": "string",
"faker": {
"generator": "file_extension"
}
}

dir_path#

{
"type": "string",
"faker": {
"generator": "dir_path"
}
}

date_time#

A date_time is a variant of the string generator type that generates values from a specified range of date_time values. This lets you, for example, generate valid days of the year for an updated_at column or a valid RFC 2822 timestamp for an email header field, among others.

You can specify a string as a date_time by using the "date_time": {...} key/value pair.

Example#

{
"type": "string",
"date_time": {
"format": "%Y-%m-%d",
"subtype": "naive_date",
"begin": "2020-01-01",
"end": "2025-01-01"
}
}

Accepted values for the "date_time" key are objects with the following keys:

  • "format": a strftime-style parameter specifying the string formatting of the underlying date_time value.
  • "subtype": one of the following
    • "naive_date": when the underlying date_time value should be a simple date without timezone specification,
    • "naive_time": when the underlying date_time value should be a simple time without timezone specification,
    • "naive_date_time": when the underlying date_time value should be a combined date and time without timezone specification,
    • "date_time": when the underlying date_time value should be a combined date and time with timezone specification.
  • "begin" and "end": the lower and upper bounds of the date_time value to generate. The formatting of these values must adhere to the strftime-string specified in the "format" field.

Not specifying begin or end will result in these defaulting to the current time.

{
"type": "string",
"date_time": {
"format": "%Y-%m-%d",
"subtype": "naive_date",
"end": "2030-01-01"
}
}

Or optionally both, will result in a constant time:

{
"type": "string",
"date_time": {
"format": "%Y-%m-%d",
"subtype": "naive_date"
}
}

Example#

{
"type": "string",
"date_time": {
"format": "%Y-%m-%dT%H:%M:%S",
"subtype": "naive_date_time",
"begin": "2015-01-01T00:00:00",
"end": "2020-01-01T12:00:00"
}
}

serialized#

serialized is a variant of the string generator type which serializes the output of a child generator into a string.

serialized has 2 fields,

  • serializer: The serializer to be used (currently only json)
  • content: The content to be serialized. This can be any valid Synth generator

Example#

{
"type": "string",
"serialized": {
"serializer": "json",
"content": {
"type": "object",
"username": {
"type": "string",
"faker": {
"generator": "name"
}
}
}
}
}

truncated#

The truncated generator truncates the output of it's inner generator to a fixed length.

If the output of its inner generator is less than or equal to the length, it is left untouched.

truncated has 2 fields,

  • length: The number of characters to truncate to. This can be any Synth generator that yields a non-negative Number.
  • content: The content to be truncated. This can be any Synth generator that yields a String.

Example#

{
"type": "string",
"truncated": {
"content": {
"type": "string",
"pattern": "[a-zA-Z0-9]{0, 255}"
},
"length": 5
}
}

categorical#

A categorical is a variant of the string generator type that generates values from a finite set of user-defined values. You can specify a string as a categorical by using the "categorical": {...} key/value pair.

Example#

{
"type": "string",
"categorical": {
"pawn": 8,
"rook": 2,
"knight": 2,
"bishop": 2,
"queen": 1,
"king": 1
}
}

The value of the "categorical" key must be an object whose:

  • keys are the allowed values of the categorical (e.g. "pawn", "rook", etc.),
  • values are non-negative integers defining the relative weight of the corresponding variant (e.g. 8, 2, etc.).