Skip to content

Error should point to the right spots where it fails to parse #2

@talegari

Description

@talegari

Failed parsing shows like this:

box::use(sr = structr)
packageVersion("structr")
#> [1] '0.1.0.9000'

schema = sr$s_map(
  x = sr$s_integer(),
  y = sr$s_double(),
  z = sr$s_optional(sr$s_string())
  ) |>
  sr$build_structure()

json_str_1 = '{"x": 1.1, "y": 99.9, "z": "value"}'
sr$parse_json(json_str_1, schema)
#> Error in `sr$parse_json()`:
#> ! ExpectedSigned at character 0

Created on 2025-04-26 with reprex v2.1.1

Error message could say something like "Expected an integer for x, but got a double". If x was nested in y, we could say "Expected foo at y$x, but got bar".


structr fills a much needed void in the R ecosystem which was lacking pydantic like schema manager. Thanks for writing this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions