### TOML Product/Item List Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/quick-reference.md An example of how to represent a list of products or items using TOML's array of tables feature. ```toml [[products]] id = 1 name = "Hammer" price = 19.99 tags = ["tool", "hardware"] [[products]] id = 2 name = "Nail" price = 0.50 tags = ["fastener", "hardware"] ``` -------------------------------- ### Real-World Key Examples in TOML Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/keys.md Provides a comprehensive set of examples showcasing various valid key types in TOML, including bare, quoted, dotted, and mixed-quoted keys. ```toml # Bare keys name = "Alice" age = 30 is_active = true # Quoted keys with spaces "first name" = "Alice" "last name" = "Smith" # Dotted keys author.name = "Tom" author.email = "tom@example.com" database.server.host = "localhost" database.server.port = 5432 # Quoted dotted keys servers."prod-1".ip = "192.168.1.1" servers."prod-2".ip = "192.168.1.2" # Mixed quoting config.database."max-connections" = 100 paths.home = "/home/user" paths."system-root" = "/" ``` -------------------------------- ### TOML Example Document Source: https://github.com/toml-lang/toml/blob/main/README.md A comprehensive example demonstrating various TOML features including key-value pairs, nested tables, arrays, dates, and comments. ```toml # This is a TOML document. title = "TOML Example" [owner] name = "Tom Preston-Werner" dob = 1979-05-27T07:32:00-08:00 # First class dates [database] server = "192.168.1.1" ports = [ 8000, 8001, 8002 ] connection_max = 5000 enabled = true [servers] # Indentation (tabs and/or spaces) is allowed but not required [servers.alpha] ip = "10.0.0.1" dc = "eqdc10" [servers.beta] ip = "10.0.0.2" dc = "eqdc10" [clients] data = [ ["gamma", "delta"], [1, 2] ] # Line breaks are OK when inside arrays hosts = [ "alpha", "omega" ] ``` -------------------------------- ### Complete TOML Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/README.md A comprehensive example illustrating various TOML features including comments, key-value pairs, tables, arrays, and arrays of tables. ```toml # This is a TOML document title = "TOML Specification" [owner] name = "Tom Preston-Werner" dob = 1979-05-27T07:32:00-08:00 [database] server = "192.168.1.1" ports = [ 8000, 8001, 8002 ] connection_max = 5000 enabled = true [[products]] name = "Hammer" sku = 738594937 [[products]] name = "Nail" sku = 284758393 color = "gray" ``` -------------------------------- ### Binary Integer Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/numbers.md Examples of binary integers using `0b` or `0B` prefix. Underscores are allowed between digits. ```toml bin1 = 0b11010110 bin2 = 0b1010_0011 ``` -------------------------------- ### Local Date Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/datetime.md Illustrative examples of Local Date values for various use cases like birthdays and release dates. ```toml # Simple dates birthday = 1979-05-27 release_date = 2023-06-05 expiration = 2024-12-31 # New Year's Day newyear = 2024-01-01 ``` -------------------------------- ### Products Configuration with Array of Tables and Subtables Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/tables.md An example of a products configuration using arrays of tables and nested subtables. ```toml [[products]] id = 1 name = "Hammer" sku = 738594937 [[products]] id = 2 name = "Nail" sku = 284758393 color = "gray" [products.details] weight = 0.5 unit = "kg" ``` -------------------------------- ### Nested Configuration Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/arrays.md Illustrates nested configuration using arrays of inline tables within tables. ```toml [database] connections = [ { name = "primary", host = "db1.example.com" }, { name = "replica", host = "db2.example.com" } ] [logging] handlers = [ { type = "file", path = "/var/log/app.log" }, { type = "stdout", level = "info" } ] ``` -------------------------------- ### Configuration Lists Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/arrays.md Demonstrates using arrays to represent lists of configuration items like servers, ports, and features. ```toml # Servers servers = [ { host = "alpha", port = 8001 }, { host = "beta", port = 8002 }, { host = "gamma", port = 8003 } ] # Port numbers ports = [ 8000, 8001, 8002 ] # Features features = [ "auth", "logging", "caching" ] ``` -------------------------------- ### Local Date-Time Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/datetime.md Various examples of Local Date-Time values, showing standard format, milliseconds, omitted seconds, and space delimiter. ```toml # Standard local date-time local = 1979-05-27T07:32:00 # With milliseconds with_ms = 2023-06-05T14:30:45.123 # Seconds omitted no_secs = 2023-06-05T14:30 # Space delimiter space_delim = 2023-06-05 14:30:45 ``` -------------------------------- ### Multi-line Basic String Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/strings.md Provides examples of multi-line basic TOML strings, including those with line-ending backslashes and explicit newlines. ```toml # Multi-line basic string str1 = """ Roses are red Violets are blue""" # With line-ending backslash str2 = """ The quick brown \ fox jumps over \ the lazy dog.""" # With escapes str3 = """First line\nSecond line""" ``` -------------------------------- ### TOML Date-Time Type Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/datetime.md Demonstrates the syntax for all four TOML date-time types: Offset Date-Time, Local Date-Time, Local Date, and Local Time, along with real-world configuration examples. ```toml # All four types offset_dt = 1979-05-27T07:32:00-07:00 # Specific instant local_dt = 1979-05-27T07:32:00 # Calendar time local_date = 1979-05-27 # Calendar day local_time = 07:32:00 # Clock time # Real-world config server_start_time = 2023-06-05T09:00:00Z maintenance_date = 2023-12-25 business_hours_start = 09:00:00 contract_signed = 2023-01-15 ``` -------------------------------- ### Basic String Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/strings.md Illustrates valid basic TOML strings, including paths with backslashes and Unicode characters. ```toml str1 = "Hello" str2 = "Path: C:\\Users\\name" str3 = "Tab\there" str4 = "Unicode: αβγ" ``` -------------------------------- ### Local Date Syntax Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/datetime.md Basic syntax examples for Local Date values. ```toml ld1 = 1979-05-27 ld2 = 2023-06-05 ``` -------------------------------- ### Octal Integer Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/numbers.md Examples of octal integers using `0o` or `0O` prefix. Underscores are allowed between digits. ```toml oct1 = 0o01234567 oct2 = 0o755 # Unix file permissions ``` -------------------------------- ### Basic String Quoted Key Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/keys.md Shows examples of quoted keys using basic strings, which allow spaces, special characters, Unicode, and escape sequences. ```toml "127.0.0.1" = "value" "character encoding" = "value" "ʎǝʞ" = "value" "key with \"quotes\"" = "value" "C:\\path\\to\\file" = "value" ``` -------------------------------- ### TOML Configuration File Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/quick-reference.md A common pattern for structuring a TOML configuration file, including application settings, database details, and logging configurations. ```toml [app] name = "MyApp" version = "1.0.0" [database] host = "localhost" port = 5432 credentials = {user = "admin", password = "secret"} [logging] level = "info" handlers = ["console", "file"] ``` -------------------------------- ### Multi-Handler Logging Setup Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Configures multiple logging handlers with different types, levels, and formats. ```toml [[logging.handlers]] type = "console" level = "info" format = "text" [[logging.handlers]] type = "file" level = "warning" path = "/var/log/warnings.log" format = "json" [[logging.handlers]] type = "syslog" level = "error" facility = "local0" [logging] default_level = "info" ``` -------------------------------- ### Real-World TOML Configuration Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/tables.md A comprehensive TOML configuration structure including root, standard, nested, inline tables, and arrays of tables. ```toml # Root table title = "TOML Configuration" # Standard table [database] server = "192.168.1.1" ports = [ 8000, 8001, 8002 ] enabled = true # Nested tables [database.connection] max_retries = 3 timeout = 5 # Inline table [app] metadata = { version = "1.0", build = "2023-06-05" } # Array of tables [[database.pools]] name = "primary" capacity = 20 [[database.pools]] name = "replica" capacity = 10 ``` -------------------------------- ### Offset Date-Time Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/datetime.md Various examples of Offset Date-Time values, including different timezone offsets and precision levels. ```toml # With timezone rfc3339_full = 1979-05-27T07:32:00.5-07:00 # With milliseconds millis = 2023-06-05T14:30:45.123Z # UTC timezone utc_time = 2023-06-05T14:30:45Z # Positive offset plus_offset = 2023-06-05T14:30:45+05:30 # Seconds omitted no_seconds = 2023-06-05T14:30Z ``` -------------------------------- ### TOML Local Time Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/datetime.md Provides examples of various local time formats, including standard times, times with milliseconds, and times with omitted seconds. ```toml # Standard times breakfast = 08:00:00 lunch = 12:30:00 dinner = 19:00:00 # With milliseconds alarm = 06:30:00.500 # Seconds omitted office_opens = 09:00 office_closes = 17:30 ``` -------------------------------- ### TOML Database URLs Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/quick-reference.md Shows how to represent database connection information in TOML, including a connection string and individual connection parameters. ```toml [database] # Connect string connection = "postgresql://user:pass@localhost/dbname" # Connection details server = "localhost" port = 5432 name = "mydb" user = "admin" password = "secret" ``` -------------------------------- ### Array of Inline Tables Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/arrays.md A practical example of an array containing multiple inline tables, often used for lists of configuration items. ```toml # Array of inline tables products = [ { id = 1, name = "Widget", price = 19.99 }, { id = 2, name = "Gadget", price = 39.99 }, { id = 3, name = "Gizmo", price = 59.99 } ] ``` -------------------------------- ### Hexadecimal Integer Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/numbers.md Examples of hexadecimal integers using `0x` or `0X` prefix. Underscores are allowed between digits. ```toml hex1 = 0xDEADBEEF hex2 = 0xdeadbeef hex3 = 0xdead_beef ``` -------------------------------- ### Unix/Linux File Permission Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/configuration.md Demonstrates how to set file permissions for TOML configuration files using the `chmod` command on Unix-like systems. ```bash # Standard configuration chmod 644 config.toml # Sensitive configuration with secrets chmod 600 secrets.toml # Directory containing configs chmod 755 /etc/myapp/config/ ``` -------------------------------- ### Python pyproject.toml Minimal Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md A minimal TOML configuration for a Python project, defining project metadata and build system requirements. ```toml [project] name = "my-package" version = "1.0.0" description = "A sample package" authors = [{name = "Alice", email = "alice@example.com"}] [build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" [project.optional-dependencies] dev = ["pytest", "black", "flake8"] docs = ["sphinx"] ``` -------------------------------- ### Top-Level Table Example Source: https://github.com/toml-lang/toml/blob/main/toml.md Demonstrates the structure of the top-level (root) table, which precedes the first explicit table header. ```toml # Top-level table begins. name = "Fido" breed = "pug" # Top-level table ends. [owner] name = "Regina Dogman" member_since = 1999-08-04 ``` -------------------------------- ### Example TOML Document Source: https://github.com/toml-lang/toml/blob/main/_autodocs/abnf-grammar.md A sample TOML document used for testing the ABNF grammar. This example showcases various TOML data types and structures. ```toml # This is a TOML document. title = "TOML Example" [owner] name = "Tom Preston-Werner" dob = 1979-05-27T07:32:00-08:00 [database] server = "192.168.1.1" ports = [ 8000, 8001, 8002 ] enabled = true ``` -------------------------------- ### Literal String Syntax Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/strings.md Illustrates the syntax of literal TOML strings, showing paths, regex, and quoted names. ```toml winpath = 'C:\\Users\\nodejs\\templates' regex = '<\i\c*\s*>' quoted = 'Tom "Dubs" Preston-Werner' ``` -------------------------------- ### Root Table Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/tables.md Shows the structure of the root table, which contains key/value pairs at the beginning of the document before any table headers. ```toml # Root table starts here name = "Fido" breed = "pug" # Root table ends here [owner] name = "Regina Dogman" member_since = 1999-08-04 ``` -------------------------------- ### TOML Valid Key/Value Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/syntax.md Demonstrates valid TOML key/value pairs with various data types including strings, integers, floats, booleans, offset date-times, arrays, and inline tables. Includes examples of bare, dotted, and quoted keys. ```TOML # Bare key with string value title = "TOML Spec" # Dotted key creating nested tables database.server = "localhost" # Various value types count = 42 # Integer ratio = 3.14 # Float enabled = true # Boolean timestamp = 2023-06-05T10:30:00Z # Offset Date-Time products = [ "A", "B", "C" ] # Array config = { x = 1, y = 2 } # Inline Table ``` -------------------------------- ### TOML Date and Time Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Illustrates various date and time formats in TOML, including times, datetimes with timezone, and local datetimes. ```toml # Application start/stop times start_time = 09:00:00 stop_time = 17:30:00 # Maintenance window (UTC) maintenance = 2024-12-25T02:00:00Z # Local deployment time (no timezone) deployment = 2024-06-15T14:30:00 # Important dates founding_date = 1979-05-27 current_date = 2024-06-05 ``` -------------------------------- ### Local Date-Time Syntax Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/datetime.md Examples of Local Date-Time syntax, including fractional seconds. ```toml ldt1 = 1979-05-27T07:32:00 ldt2 = 1979-05-27T07:32:00.5 ldt3 = 1979-05-27T00:32:00.999999 ``` -------------------------------- ### Data Structures Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/arrays.md Shows arrays used for common data structures like coordinates and schedules. ```toml # Coordinates coordinates = [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] # Schedule schedule = [ { day = "Monday", hours = 9 }, { day = "Tuesday", hours = 9 }, { day = "Wednesday", hours = 9 } ] ``` -------------------------------- ### Minimal TOML Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/README.md Shows a minimal valid TOML document, which can be empty or contain only comments and a single key-value pair. ```toml # Empty file or just comments is valid key = "value" ``` -------------------------------- ### TOML Comment Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/syntax.md Provides examples of different types of comments in TOML, including explanatory full-line comments, inline comments with details, comments for table headers, and commented-out configuration values. ```TOML # Full-line comment explaining configuration server = "localhost" # Inline comment with detail # Configuration sections [database] # Database settings host = "db.example.com" # Disabled values (commented out) # backup_dir = "/mnt/backup" ``` -------------------------------- ### Table Ordering Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/tables.md A TOML table demonstrating key/value pairs. While keys within a table are not guaranteed to be ordered, tables themselves appear in document order. ```toml [database] server = "192.168.1.1" ports = [ 8000, 8001, 8002 ] connection_max = 5000 enabled = true ``` -------------------------------- ### TOML String Type Selection Guide Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/strings.md A guide to selecting the appropriate TOML string type based on requirements such as escaping, multiline content, and special characters. ```toml # Text with special characters "Hello\nWorld" # Long text with escaping """Line 1\nLine 2""" # Path or regex (no escaping) 'C:\path\file' # Multiline raw text '''regex\d{2}pattern''' ``` -------------------------------- ### Bare Key Syntax Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/keys.md Demonstrates the valid syntax for bare keys, including letters, digits, underscores, and dashes. Note that keys composed entirely of digits are valid bare keys and are always interpreted as strings. ```toml key = "value" bare_key = "value" bare-key = "value" _underscore = "value" key123 = "value" 123 = "value" # all digits is allowed ``` -------------------------------- ### Nested Tables Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/tables.md Demonstrates nested tables using dotted notation in headers. This allows for hierarchical data structures. ```toml [owner] name = "Tom Preston-Werner" dob = 1979-05-27T07:32:00-08:00 [database] server = "192.168.1.1" ports = [ 8000, 8001, 8002 ] [servers.alpha] ip = "10.0.0.1" dc = "eqdc10" [servers.beta] ip = "10.0.0.2" dc = "eqdc10" ``` -------------------------------- ### TOML Root Table Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/syntax.md Illustrates a TOML document with a root table containing key/value pairs and a subsequent table section with its own key/value pairs. ```TOML # Root table name = "value" count = 42 # Comment [section] key = "value" ``` -------------------------------- ### Array Examples Source: https://github.com/toml-lang/toml/blob/main/toml.md Ordered lists of values enclosed in square brackets. Elements are comma-separated and whitespace is ignored. Mixed types are permitted. ```toml integers = [ 1, 2, 3 ] colors = [ "red", "yellow", "green" ] nested_arrays_of_ints = [ [ 1, 2 ], [3, 4, 5] ] nested_mixed_array = [ [ 1, 2 ], ["a", "b", "c"] ] string_array = [ "all", 'strings', """are the same""", '''type''' ] # Mixed-type arrays are allowed numbers = [ 0.1, 0.2, 0.5, 1, 2, 5 ] contributors = [ "Foo Bar ", { name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" } ] ``` -------------------------------- ### TOML Numeric Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/numbers.md Demonstrates the syntax for various integer and float types in TOML, including different bases for integers and scientific notation for floats. Underscores are shown for readability. ```toml # Integers int_decimal = 42 int_hex = 0xDEADBEEF int_octal = 0o755 int_binary = 0b1010 # Floats float_decimal = 3.1415 float_exponent = 6.626e-34 float_special = inf # Readability large_int = 1_000_000 pi = 3.14159_26535 ``` -------------------------------- ### JSON Equivalence for Array of Tables Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/tables.md Shows the JSON representation of the TOML array of tables example. ```json { "product": [ { "name": "Hammer", "sku": 738594937 }, { "name": "Nail", "sku": 284758393, "color": "gray" } ] } ``` -------------------------------- ### Dotted Key Syntax Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/keys.md Shows the basic syntax of dotted keys, which are sequences of bare or quoted keys joined by dots, used for creating nested structures. ```toml name = "Orange" physical.color = "orange" physical.shape = "round" site."google.com" = true ``` -------------------------------- ### JSON structure from Dotted Keys Source: https://github.com/toml-lang/toml/blob/main/toml.md Illustrates the JSON structure that corresponds to the TOML dotted keys example, showing how nesting is represented. ```json { "name": "Orange", "physical": { "color": "orange", "shape": "round" }, "site": { "google.com": true } } ``` -------------------------------- ### TOML Nested Structure Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/quick-reference.md Demonstrates a nested structure in TOML, suitable for configurations like servers with nested settings and arrays of routes. ```toml [server] address = "0.0.0.0" port = 8080 [server.ssl] enabled = true certificate = "/path/to/cert.pem" [[server.routes]] path = "/api" handler = "api" [[server.routes]] path = "/web" handler = "web" ``` -------------------------------- ### Example TOML Filenames Source: https://github.com/toml-lang/toml/blob/main/_autodocs/configuration.md Commonly used filenames for TOML configuration files across different projects and purposes. ```plaintext application.toml settings.toml config.toml config/app.toml config/database.toml pyproject.toml Cargo.toml Pipfile.toml ``` -------------------------------- ### Multiline Nested Arrays Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/arrays.md Provides an example of a multiline nested array for improved readability. ```toml matrix = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ``` -------------------------------- ### Offset Date-Time Syntax Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/datetime.md Examples of Offset Date-Time syntax, including UTC, negative, and positive offsets, with and without fractional seconds. ```toml odt1 = 1979-05-27T07:32:00Z odt2 = 1979-05-27T00:32:00-07:00 odt3 = 1979-05-27T00:32:00.5-07:00 odt4 = 1979-05-27T00:32:00.999999-07:00 ``` -------------------------------- ### Inline Table Syntax Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/tables.md Provides examples of inline tables, which offer a compact, single-line syntax for key/value pairs within curly braces. ```toml name = { first = "Tom", last = "Preston-Werner" } point = { x = 1, y = 2 } animal = { type.name = "pug" } ``` -------------------------------- ### TOML Dotted Keys Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/README.md Demonstrates how dotted keys create nested table structures implicitly. This is useful for defining hierarchical data in a concise manner. ```toml database.server.host = "localhost" # Creates: { database: { server: { host: "localhost" } } } ``` -------------------------------- ### TOML Multi-line Literal String Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/strings.md Demonstrates the usage of multi-line literal strings for text, regex patterns, and UNC paths, highlighting preserved indentation and lack of escaping. ```toml # Multi-line literal text = ''' The first newline is trimmed. Indentation is preserved. No escaping allowed: \d{2} ''' # Regex pattern regex = '''I [dw]on't need \d{2} apples''' # Windows UNC path path = '''\\ServerX\admin$\system32\''' ``` -------------------------------- ### Discouraged Key Ordering Source: https://github.com/toml-lang/toml/blob/main/_autodocs/validation-rules.md Presents an example of defining dotted keys out-of-order, which is valid but discouraged in favor of a more readable, sequential definition. ```toml # Valid but discouraged apple.type = "fruit" orange.type = "fruit" apple.skin = "thin" orange.skin = "thick" # Recommended apple.type = "fruit" apple.skin = "thin" orange.type = "fruit" orange.skin = "thick" ``` -------------------------------- ### Validation Schema Configuration Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Example configuration for data validation, specifying patterns, lengths, and requirements for fields like email, password, and phone. ```toml [validation] # Example of configuration that could be used for data validation [validation.email] pattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$" required = true max_length = 254 [validation.password] min_length = 8 require_uppercase = true require_numbers = true require_special = true [validation.phone] pattern = "^\\+?[1-9]\\d{1,14}$" required = false ``` -------------------------------- ### TOML Table Header Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/syntax.md Illustrates the usage of standard and array of tables headers in TOML to define nested tables and arrays of tables, respectively. ```TOML [section] key = "value" [section.subsection] nested = "value" [[items]] name = "Item 1" [[items]] name = "Item 2" ``` -------------------------------- ### TOML Standard Table Validation Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/validation-rules.md Illustrates the creation of nested tables using dotted keys. Parent tables are automatically created if they do not exist. ```toml # Valid: auto-creates [x] and [x.y] [x.y.z] key = "value" [x] other = "value" ``` -------------------------------- ### Deeply Nested Table Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/tables.md An example of a deeply nested table, valid as long as it remains within implementation-defined limits. ```toml # Deeply nested (valid if within implementation limits) [a.b.c.d.e.f.g.h] key = "value" ``` -------------------------------- ### Blog Configuration with Categories and Authors Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Sets up blog metadata, including pagination and structured lists for categories and authors. ```toml [blog] title = "My Tech Blog" description = "Articles about software development" url = "https://blog.example.com" posts_per_page = 10 [[blog.categories]] name = "Python" slug = "python" description = "Python programming" [[blog.categories]] name = "Web Development" slug = "web-dev" description = "Web frameworks and technologies" [[blog.authors]] name = "Alice Smith" email = "alice@example.com" bio = "Full-stack developer" [[blog.authors]] name = "Bob Johnson" email = "bob@example.com" bio = "DevOps engineer" ``` -------------------------------- ### Heterogeneous Array Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/types.md Demonstrates a TOML array containing values of various types, including integers, strings, floats, booleans, nested arrays, and inline tables. ```toml mixed = [ 1, "two", 3.0, true, [ 4, 5 ], { key = "value" } ] ``` -------------------------------- ### TOML Quoted Keys Example Source: https://github.com/toml-lang/toml/blob/main/toml.md Illustrates the use of quoted keys, which follow the rules of basic or literal strings, allowing a wider range of characters for key names. ```toml "127.0.0.1" = "value" ``` ```toml "character encoding" = "value" ``` ```toml "ʎǝʞ" = "value" ``` ```toml 'key2' = "value" ``` ```toml 'quoted "value"' = "value" ``` -------------------------------- ### Invalid Float Syntax Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/numbers.md Illustrates common syntax errors for floats, such as missing digits around the decimal point or in the exponent. ```toml # Missing digit on one side of decimal point invalid1 = .5 # INVALID invalid2 = 5. # INVALID # Missing digit between decimal and exponent invalid3 = 3.e+20 # INVALID # Missing required exponent digits invalid4 = 1e # INVALID ``` -------------------------------- ### Decimal Float Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/numbers.md Basic decimal float notation with an optional sign and a fractional part. The decimal point must be surrounded by digits. ```toml flt1 = +1.0 flt2 = 3.1415 flt3 = -0.01 ``` -------------------------------- ### Float Exponential Notation Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/numbers.md Floats using exponential notation with `E` or `e` followed by an integer exponent. Supports optional signs. ```toml flt4 = 5e+22 flt5 = 1e06 flt6 = -2E-2 flt7 = 6.626e-34 ``` -------------------------------- ### TOML Float Types Source: https://github.com/toml-lang/toml/blob/main/_autodocs/types.md Shows examples of TOML float definitions, including fractional, exponential, and combined notations. Also demonstrates special float values like infinity and NaN. ```TOML fractional = 3.1415 decimal = 0.5 exponent = 6.626e-34 scientific = 1e10 combined = 6.626e-34 positive_inf = inf negative_inf = -inf not_a_number = nan ``` -------------------------------- ### Consistent Formatting Best Practice Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Illustrates consistent spacing and indentation for TOML configuration files. ```toml # Consistent spacing and indentation [section] key1 = "value" key2 = 123 key3 = true [section.subsection] nested_key = "nested_value" ``` -------------------------------- ### TOML Newline Handling Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/syntax.md Shows examples of LF and CRLF newline characters, which are treated identically by TOML parsers. Also demonstrates the use of multiline strings for explicit line breaks. ```TOML # LF newline key = "value" # CRLF newline (Windows) key = "value" # Multi-line value text = """ Line 1 Line 2 """ ``` -------------------------------- ### Commenting Style Best Practice Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Demonstrates descriptive comments for configuration sections and individual settings. ```toml # Good: descriptive comments [database] # Primary database connection host = "db.example.com" port = 5432 # Connection pool settings pool_min = 5 pool_max = 20 # SSL configuration ssl = true ``` -------------------------------- ### TOML Invalid Key/Value Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/syntax.md Highlights common invalid TOML key/value pair syntaxes, including missing values, newlines within values, incorrect separators, and duplicate keys within the same scope. ```TOML # Invalid: unspecified value key = # Invalid: newline in middle key = "value more" # Invalid: wrong separator key : "value" # Invalid: key appears twice name = "Alice" name = "Bob" ``` -------------------------------- ### Literal String Quoted Key Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/keys.md Demonstrates quoted keys using literal strings, enclosed in single quotes, which do not process escape sequences and allow most special characters. ```toml 'single-quoted key' = "value" 'key2' = "value" 'quoted "value"' = "value" 'C:\path\file' = "value" # backslash is literal ``` -------------------------------- ### Valid Array Elements Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/arrays.md Provides examples of arrays containing various TOML value types, including strings, numbers, booleans, dates, nested arrays, and inline tables. ```toml String | `["hello", "world"]` ``` ```toml Integer | `[1, 2, 3]` ``` ```toml Float | `[3.14, 2.71]` ``` ```toml Boolean | `[true, false]` ``` ```toml Offset Date-Time | `[1979-05-27T07:32:00Z]` ``` ```toml Local Date-Time | `[1979-05-27T07:32:00]` ``` ```toml Local Date | `[1979-05-27]` ``` ```toml Local Time | `[07:32:00]` ``` ```toml Array | `[[1, 2], [3, 4]]` ``` ```toml Inline Table | `[{name="Alice"}]` ``` -------------------------------- ### TOML Invalid Literal String Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/strings.md This example shows an invalid TOML literal string due to three consecutive apostrophes. It demonstrates the need to use basic or multi-line basic strings for such cases. ```toml # Invalid: 3 consecutive quotes # apos3 = '''three: ''' # Valid: use basic or literal string apos3 = "Here are fifteen apostrophes: '''''''''''''''" ``` -------------------------------- ### Same Type Arrays Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/arrays.md Examples of arrays containing elements of a single, consistent type. ```toml integers = [ 1, 2, 3 ] strings = [ "a", "b", "c" ] booleans = [ true, false, true ] floats = [ 3.14, 2.71 ] ``` -------------------------------- ### Local Date Example Source: https://github.com/toml-lang/toml/blob/main/toml.md Represents an entire day without any relation to an offset or timezone. ```toml ld1 = 1979-05-27 ``` -------------------------------- ### Environment-Specific TOML Configurations Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Demonstrates separate TOML files for production and development environments, highlighting differences in server and database settings. ```toml # config.prod.toml [server] host = "prod.example.com" port = 443 debug = false [database] host = "prod-db.example.com" pool_size = 20 ssl = true ``` ```toml # config.dev.toml [server] host = "localhost" port = 8080 debug = true [database] host = "localhost" pool_size = 5 ssl = false ``` -------------------------------- ### Basic String Syntax Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/strings.md Demonstrates the syntax of a basic TOML string, including quotes, tabs, and newlines. ```toml str = "I'm a string. \"You can quote me\". Name\tJosé\nLocation\tSF." ``` -------------------------------- ### Inline Tables in Array Source: https://github.com/toml-lang/toml/blob/main/toml.md Example of using inline tables within an array to define complex data structures concisely. ```toml points = [ { x = 1, y = 2, z = 3 }, { x = 7, y = 8, z = 9 }, { x = 2, y = 4, z = 8 } ] ``` -------------------------------- ### TOML Event Scheduling with Timezones Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Shows how to configure event details including date, time, and timezone offset, as well as registration opening and closing times. ```toml [event] name = "Conference 2024" date = 2024-06-15 start_time = 09:00:00 end_time = 17:30:00 timezone_offset = "+05:30" # With server timestamp registration_opened = 2024-01-15T10:00:00-08:00 registration_closed = 2024-06-01T23:59:59-08:00 ``` -------------------------------- ### Simple TOML Arrays Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Examples of simple arrays in TOML, including arrays of integers, strings, and mixed data types. ```toml # Port numbers ports = [8000, 8001, 8002] # Features features = ["authentication", "logging", "caching"] # Mixed types (allowed but unusual) mixed = [1, "two", 3.0, true] ``` -------------------------------- ### Basic TOML Structure Source: https://github.com/toml-lang/toml/blob/main/_autodocs/quick-reference.md Demonstrates root-level key-value pairs, comments, and basic table definitions. ```toml # 1. Root-level configuration at top app_name = "Example" version = "1.0.0" # 2. Comments before sections # Core application settings [core] setting1 = "value1" # 3. Related sections together [database] host = "localhost" [database.backup] enabled = true # 4. Arrays of tables at end [[service]] name = "api" [[service]] name = "web" ``` -------------------------------- ### Invalid Quoted Keys Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/keys.md Highlights examples of invalid quoted keys, including multi-line strings and unquoted empty keys. ```toml # Multi-line strings cannot be keys """key""" = "not allowed" # INVALID '''key''' = "not allowed" # INVALID # Unquoted empty key = "no key" # INVALID ``` -------------------------------- ### Simple TOML Configuration Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md A basic TOML file for application configuration, including application name, version, debug flag, and server settings. ```toml # Application configuration app_name = "MyApplication" version = "1.0.0" debug = false [server] host = "0.0.0.0" port = 8080 workers = 4 timeout = 30 ``` -------------------------------- ### Inline Table for Nested Structure Source: https://github.com/toml-lang/toml/blob/main/toml.md An example of using an inline table to define a nested structure, similar to standard tables but more compact. ```toml type = { name = "Nail" } ``` -------------------------------- ### Rust Cargo.toml Package Definition Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md A TOML configuration for a Rust project's package, including dependencies, dev-dependencies, binaries, and examples. ```toml [package] name = "my-project" version = "0.1.0" edition = "2021" authors = ["Alice "] [dependencies] serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.0", features = ["full"] } [dev-dependencies] criterion = "0.5" [[bin]] name = "my-app" path = "src/main.rs" [[example]] name = "demo" path = "examples/demo.rs" ``` -------------------------------- ### TOML Array of Tables with Subtables Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Demonstrates an array of tables, where each element is a server, and includes subtables for server capabilities. ```toml # Servers [[servers]] name = "alpha" ip = "10.0.0.1" dc = "us-east" [servers.capabilities] ssl = true compression = true caching = false [[servers]] name = "beta" ip = "10.0.0.2" dc = "us-west" [servers.capabilities] ssl = true compression = false caching = true ``` -------------------------------- ### Invalid Bare Keys Source: https://github.com/toml-lang/toml/blob/main/_autodocs/validation-rules.md Shows examples of invalid bare keys that violate TOML syntax rules, such as containing spaces or dots. ```toml # Invalid # with space = "value" # with.dot = "value" (this is dotted key syntax) ``` -------------------------------- ### TOML Multiple Database Configurations Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Sets up configurations for multiple databases, including primary, replica, and analytics databases, each with specific pool sizes and read-only settings. ```toml [databases] [databases.primary] host = "primary.db.local" port = 5432 pool_size = 20 read_only = false [databases.replica] host = "replica.db.local" port = 5432 pool_size = 10 read_only = true [databases.analytics] host = "analytics.db.local" port = 5432 pool_size = 5 read_only = true ``` -------------------------------- ### Basic Array Syntax Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/arrays.md Demonstrates the fundamental syntax for defining arrays of integers, strings, nested arrays, and mixed types. ```toml integers = [ 1, 2, 3 ] colors = [ "red", "yellow", "green" ] nested = [ [ 1, 2 ], [ 3, 4, 5 ] ] mixed_types = [ 1, "two", 3.0, true ] ``` -------------------------------- ### Variable Substitution Placeholders Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Illustrates how placeholders for environment variables might be used in configuration. Note that TOML itself does not perform substitution. ```toml # Note: TOML itself doesn't support variable substitution # This must be handled by the consuming application # Example showing placeholder pattern [database] host = "${DB_HOST}" port = 5432 username = "${DB_USER}" password = "${DB_PASSWORD}" [api] key = "${API_KEY}" secret = "${API_SECRET}" ``` -------------------------------- ### Invalid TOML: Subtable Parent Order Source: https://github.com/toml-lang/toml/blob/main/toml.md An example of invalid TOML where a subtable is defined before its parent array element. This will cause a parse error. ```toml # INVALID TOML DOC [fruit.physical] # subtable, but to which parent element should it belong? color = "red" shape = "round" [[fruit]] # parser must throw an error upon discovering that "fruit" is # an array rather than a table name = "apple" ``` -------------------------------- ### Multi-line Basic String Equivalents Source: https://github.com/toml-lang/toml/blob/main/toml.md Illustrates how multi-line basic strings might be interpreted on different operating systems, showing newline normalization. ```toml # On a Unix system, the above multi-line string will most likely be the same as: str2 = "Roses are red\nViolets are blue" # On a Windows system, it will most likely be equivalent to: str3 = "Roses are red\r\nViolets are blue" ``` -------------------------------- ### TOML Local Time Syntax Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/datetime.md Illustrates the basic syntax for representing local time in TOML, including hours, minutes, seconds, and fractional seconds. ```toml lt1 = 07:32:00 lt2 = 00:32:00.5 lt3 = 00:32:00.999999 ``` -------------------------------- ### Multiple Standard Tables Source: https://github.com/toml-lang/toml/blob/main/_autodocs/api-reference/tables.md Shows how multiple standard tables are defined, with key/value pairs belonging to each table until the next header. ```toml [table1] key1 = "value1" key2 = 123 [table2] key1 = "different value" key2 = 456 ``` -------------------------------- ### TOML Local Date Types Source: https://github.com/toml-lang/toml/blob/main/_autodocs/types.md Examples of TOML local date values, representing a calendar date without time or timezone information. ```TOML date = 1979-05-27 today = 2023-06-05 ``` -------------------------------- ### Basic TOML Strings Source: https://github.com/toml-lang/toml/blob/main/toml.md Illustrates basic TOML string syntax, including single-quoted literal strings and handling of special characters. ```toml winpath = 'C:\\Users\\nodejs\\templates' winpath2 = '\\ServerX\\admin$\\system32\'' quoted = 'Tom "Dubs" Preston-Werner' regex = '<\i\c*\s*>' ``` -------------------------------- ### TOML Inline Table Validation Examples Source: https://github.com/toml-lang/toml/blob/main/_autodocs/validation-rules.md Shows valid and invalid uses of inline tables. Inline tables are self-contained and cannot extend standard tables. ```toml # Valid config = { host = "localhost", port = 5432 } # Invalid [section] table = { key = "value" } # table.newkey = "value" # Cannot extend # Invalid [section] config.host = "localhost" # config = { port = 5432 } # Conflicts with section ``` -------------------------------- ### TOML Array Validation Example Source: https://github.com/toml-lang/toml/blob/main/_autodocs/validation-rules.md Demonstrates a syntactically valid TOML array with mixed data types. Implementations may enforce type homogeneity. ```toml # Syntactically valid TOML mixed = [1, "two", 3.0, true] # Consumer may accept or reject based on context ``` -------------------------------- ### Runtime Configuration Settings Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Defines application settings that might be adjusted at runtime, such as environment, debug mode, and server details. ```toml [app] # These might be replaced at runtime environment = "production" debug_mode = false log_level = "info" [server] host = "0.0.0.0" port = 8080 [cache] enabled = true ttl = 3600 ``` -------------------------------- ### TOML Extending Tables with Dotted Keys Source: https://github.com/toml-lang/toml/blob/main/toml.md Shows how to add new keys to existing or implicitly created tables using dotted keys. ```toml # This makes the key "fruit" into a table. ``` ```toml fruit.apple.smooth = true ``` ```toml ``` ```toml # So then you can add to the table "fruit" like so: ``` ```toml fruit.orange = 2 ``` -------------------------------- ### TOML Comments Source: https://github.com/toml-lang/toml/blob/main/_autodocs/abnf-grammar.md Defines the ABNF for comments, which start with '#' and extend to the end of the line. Allows specific Unicode characters and control characters like tab. ```ABNF ; Comment comment-start-symbol = %x23 ; # non-ascii = %x80-D7FF / %xE000-10FFFF non-eol = %x09 / %x20-7E / non-ascii comment = comment-start-symbol *non-eol ``` -------------------------------- ### TOML Simple Logging Configuration Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Basic logging configuration including level, format, output destination, and file-specific settings like path, rotation, and retention. ```toml [logging] level = "info" format = "json" output = "stdout" [logging.file] path = "/var/log/app.log" rotation = "daily" retention_days = 30 max_size_mb = 100 ``` -------------------------------- ### TOML Array of Objects (Users) Source: https://github.com/toml-lang/toml/blob/main/_autodocs/examples-and-patterns.md Illustrates an array of objects, where each object represents a user with properties like name, role, and email. ```toml # Users [[users]] name = "Alice" role = "admin" email = "alice@example.com" [[users]] name = "Bob" role = "user" email = "bob@example.com" [[users]] name = "Charlie" role = "user" email = "charlie@example.com" ```