Towards JSON schema from Dhall


I see there has been some discussion on JSONschema->Dhall and Dhall->JSONschema. I’m curious if there any recent developments or other places to look for hints for how to go about creating JSON schema from Dhall.

For example, I’d like to translate a Dhall object like:

{ foo : Text
, bar : Optional Text

into corresponding YAML (or JSON):

type: object
additionalProperties: false
    type: string   
    type: string   
  - foo


I’m not aware of any progress on Dhall → JSONschema, but it seems like something that would be pretty easy to do.

I did make an attempt in a few months ago at JSONschema → Dhall but stopped when I realized that the JSONschema schema was so large to handle. That direction for the conversion is significantly more difficult, in my opinion, unless you restrict yourself to a subset of JSONschema.


Thanks. That’s good to know it should be easy to do. For a Dhall record, I can see how to easily write a corresponding Dhall record that produces JSON schema. For example,

{ Type = { 
  foo : Text
, bar : Optional Text
 schema = {
  properties = {
    foo.type = 'string'
    bar.type = 'string'
 required = ['id'],
 type = 'object'

But that’s not ideal as I’m having to keep the Type and schema aligned manually (though this is far better than what we have currently).

Ideally I’d like a function that takes a Type and produces the schema. But I’m stuck on how to even map from the type Text to 'string'.


My intuition is that the conversion from Dhall to a JSONschema should be probably be implemented as an executable (e.g. dhall-to-jsonschema) rather than implementing the conversion within Dhall


Got it. I was starting to think that (but also afraid of that).