Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add json-schema support #2

Open
yvan-sraka opened this issue Jul 16, 2023 · 0 comments
Open

Add json-schema support #2

yvan-sraka opened this issue Jul 16, 2023 · 0 comments
Assignees

Comments

@yvan-sraka
Copy link
Owner

It would be nice to handle json-schema, few months ago, I played with this experiment:

{ pkgs ? import <nixpkgs> { }, data ? {
  # "productId" = 1;
  # "productName" = "A green door";
  # "price" = 12.5;
  # "tags" = [ "home" "green" ];
}, schema ? {
  # "$schema" = "https://json-schema.org/draft/2020-12/schema";
  # "$id" = "https://example.com/product.schema.json";
  # "title" = "Product";
  # "description" = "A product in the catalog";
  # "type" = "object";
} }:
with builtins;
let
  jsonData = pkgs.writeText "data.json" (toJSON data);
  jsonSchema = pkgs.writeText "schema.json" (toJSON schema);
  check = pkgs.runCommand "check-jsonschema" { } ''
    mkdir -p $out && echo 0 > $out/output
    ${pkgs.check-jsonschema}/bin/check-jsonschema --schemafile ${jsonSchema} ${jsonData} || echo $? > $out/output
  '';
  valid = readFile "${check}/output" == "0\n";
in valid # trace valid { }
@yvan-sraka yvan-sraka self-assigned this Jul 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant