Replies: 1 comment 1 reply
-
This is something we'd like to support eventually, but, this currently isn't a target use-case for Pkl. One thing you can look into is generating JSON Schema from Pkl (see https://pkl-lang.org/package-docs/pkg.pkl-lang.org/pkl-pantry/org.json_schema.contrib/current/generate/index.html). You'd then pair this with a JSON Schema validator to validate the incoming JSON. If you do this, just be aware of the limitations described by that generator. For example, the JSON Schema generator currently cannot convert constraints like Another approach you can explore is to parse the JSON into the corresponding Pkl type using deepToTyped. Once you do this, you will get validation errors on the parsed object. |
Beta Was this translation helpful? Give feedback.
-
I introduced pkl to my colleagues and as we were looking for a way to help validate Web form submissions, we immediately assumed pkl would be a good fit.
However unlike typical solutions like ajv, it wasn't super clear how to validate incoming JSON against a pkl schema.
Any clues or examples out there?
JSON schema is mentioned here: #172 (reply in thread)
But the ticket open for JSON schema doesn't seem to indicate this is straightforward: #92
Or there something I am missing?
Beta Was this translation helpful? Give feedback.
All reactions