Skip to content

Instantly share code, notes, and snippets.

@cablehead
Created January 19, 2026 16:38
Show Gist options
  • Select an option

  • Save cablehead/977f597969b166f15c269ed4ac3e5d19 to your computer and use it in GitHub Desktop.

Select an option

Save cablehead/977f597969b166f15c269ed4ac3e5d19 to your computer and use it in GitHub Desktop.

Exploring schema validation for nushell/http-nu

We want to validate records against a schema (like JSON Schema). Nushell already has type syntax for command signatures:

def foo []: record<
  name: string,
  age: int,
  email?: string,
  tags: list<string>,
  address: record<city: string, zip: int>
> -> nothing { }

This supports optional fields (?), nested records, lists, etc. But there's no first-class "type value" - it only exists in signatures.

Options for expressing schemas:

1. Command signature

def my-schema []: record<name: string, tags: list<string>, address: record<city: string>> -> nothing { }
# query via: help commands | where name == "my-schema" | get input_output

Works today without changes.

2. Type string (parsed by nushell's parser)

"record<name: string, tags: list<string>, address: record<city: string>>" | validate $data

Reuses existing nushell syntax.

3. Record-as-schema

{name: "string", tags: "list<string>", address: {city: "string"}} | validate $data

It's a real record. Would need to define semantics for nested structures.

4. New type literal

let schema = type record<name: string, tags: list<string>, address: record<city: string>>
$data | validate $schema

First-class type values. Would require nushell changes: new Type value variant, parser support for type keyword, and plumbing through the value system.

Thoughts? Which feels most nushell-native?

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