dsherret / dsherret/dax

Suggestion: Standard Schema support for `.json()`

Open
#409 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.5k
Forks
42
Avg merge
11m
Merged PRs (30d)
2

Description

Similar to https://github.com/dsherret/path/issues/22, it would be useful if `$``.json()` and `$.request().json()` allowed you to pass in a [Standard Schema](https://standardschema.dev/schema) to easily validate the JSON:

```ts
import * as v from "valibot";

const OutputSchema = v.object({ prop: v.number() });
// const { prop } = v.parse(OutputSchema, await $`echo '{ "prop": 5 }'`.json());
const { prop } = await $`echo '{ "prop": 5 }'`.json(OutputSchema);

const DPrintPlugins = v.object({
schemaVersion: v.literal(4),
latest: v.array(v.object({
// ...
})),
});
// const data = v.parse(DPrintPlugins, await $.request("https://plugins.dprint.dev/info.json").json());
const data = await $.request("https://plugins.dprint.dev/info.json").json(DPrintPlugins);
```

(This idea is [inspired by Ky](https://github.com/sindresorhus/ky/blob/3419113b48e034fdcf8fa6bd3be3da7b3d0d758f/readme.md?plain=1#L155))

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the public `.json()` entry points for shell commands and `$.request().json()`, then read how their current JSON results are typed and returned. Add support for accepting a Standard Schema as shown in the issue, and verify that the parsed result is validated and typed for both usage patterns.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.