DEV Community

scl
scl

Posted on

JSON schema parser

Been thinking about a model validation/parsing issue lately.

Background

I use JSON schema in AWS API gateway to validate the incoming event payload. If the payload gets to reach my Lambda codes downstream, those Lambda codes parse the payload into a strongly typed object using Zod.

Problem statement

How then can we prevent manual duplication and have a single source of JSON schema for API gateway (for validation) and our Lambda codes (for parsing into strongly typed objects)?

Zod doesn't really interoperate with JSON schema without some third party adapters. Hence that sent me on a search for a parser that plays well with JSON schema.

Probable solution

That search led me to a promising candidate that's used by some 30 million people:
https://ajv.js.org/guide/typescript.html#utility-type-for-jtd-data-type

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️