Skip to content

data infer-schema fails on top-level JSON arrays (documented example) #12

Description

@roll

data infer-schema / infer_data_schema fails on top-level JSON arrays (the documented example).

Environment

  • fairspec 0.1.4 (installed from PyPI)
  • Python 3.12.3, Linux
  • Reproduced in a clean virtualenv against the published wheel.

Repro

cat > users.json <<'JSON'
[
  {"id": 1, "name": "Alice", "email": "alice@example.com"},
  {"id": 2, "name": "Bob",   "email": "bob@example.com"}
]
JSON
fairspec data infer-schema users.json --json

Actual

{ "error": "Invalid descriptor: [\n  {\"id\": 1, ...}\n]\n" }

With --debug the traceback ends in fairspec_metadata/actions/descriptor/parse.py:

def parse_descriptor(text: str) -> Descriptor:
    value = json.loads(text)
    if not isinstance(value, dict):
        raise Error(f"Invalid descriptor: {text}")   # <-- top-level arrays rejected

A single top-level object ({...}) works fine.

Why it's a bug: docs/terminal/data.md documents exactly this case — fairspec data infer-schema users.json where users.json is a top-level array — and shows the expected output as {"type": "array", "items": {...}}. The data-schema path goes through parse_descriptor (descriptor parsing), which is too strict for arbitrary JSON data.

Expected: infer a Data Schema from any valid JSON value, including a top-level array.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions