dhall-json: implement --type mode for encoding type as json #2666
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
I'm working on a project where we are generating datatypes for a given Dhall schema. It would be helpful for us if dhall-json could generate a JSON representation of types, as well as values. Would you be interested in adding something like this?
This PR has two changes: I've modified dhallToJSON to be able to emit value types, and added a
--type
option todhall-to-json
.I think this representation should be unambiguous and round-trippable, but I'm happy to use any representation. I have only briefly read about JSON schemas, to be honest, but I thought that a Dhall-specific type encoding would be better to faithfully preserve the original Dhall type.
The extra
--type
option is just a shorthand which might be useful, but we can easily make do without the option if it's not likely to be useful to anyone else.Here's an example showing how the output looks: for an input schema:
This gives the following JSON type: