RJR
Convex Community4y ago
29 replies
RJ

JSON in Schemas

There isn't a way to describe JSON as a SchemaType, is there? I mean something like the following—except of course that it doesn't loop indefinitely!

function json() {
  return s.union(
    s.boolean(),
    s.number(),
    s.string(),
    s.null(),
    jsonArray(),
    jsonObject()
  );
}
function jsonArray() {
  return s.array(json());
}
function jsonObject() {
  return s.map(s.string(), json());
}
Was this page helpful?