Skip to contents

Creates a structure definition for a JSON object with named fields. Each field must be defined using an s_* function (e.g., s_string(), s_integer(), or nested structures).

Usage

s_map(..., .ignore_extra_fields = FALSE)

Arguments

...

Named field definitions. Each name corresponds to a key in the JSON object, and each value must be a structure created by an s_* function. Call s_map() with no arguments to define an empty object.

.ignore_extra_fields

Logical (default FALSE). If TRUE, allows extra fields in the input JSON to be ignored instead of triggering a validation error.

Value

An intermediate structure definition used by build_structure().

Examples

# Simple object
s_map(name = s_string(), age = s_integer())
#> $type
#> [1] "map"
#> 
#> $value
#> $value$name
#> $value$name$type
#> [1] "string"
#> 
#> 
#> $value$age
#> $value$age$type
#> [1] "integer"
#> 
#> 
#> 
#> $ignore_extra_fields
#> [1] FALSE
#> 

# Nested structure
s_map(
  user = s_string(),
  details = s_map(email = s_string(), active = s_logical()),
  tags = s_vector(s_string())
)
#> $type
#> [1] "map"
#> 
#> $value
#> $value$user
#> $value$user$type
#> [1] "string"
#> 
#> 
#> $value$details
#> $value$details$type
#> [1] "map"
#> 
#> $value$details$value
#> $value$details$value$email
#> $value$details$value$email$type
#> [1] "string"
#> 
#> 
#> $value$details$value$active
#> $value$details$value$active$type
#> [1] "logical"
#> 
#> 
#> 
#> $value$details$ignore_extra_fields
#> [1] FALSE
#> 
#> 
#> $value$tags
#> $value$tags$type
#> [1] "vector"
#> 
#> $value$tags$value
#> $value$tags$value$type
#> [1] "string"
#> 
#> 
#> 
#> 
#> $ignore_extra_fields
#> [1] FALSE
#> 

# Ignore extra JSON fields
s_map(id = s_integer(), .ignore_extra_fields = TRUE)
#> $type
#> [1] "map"
#> 
#> $value
#> $value$id
#> $value$id$type
#> [1] "integer"
#> 
#> 
#> 
#> $ignore_extra_fields
#> [1] TRUE
#>