-
Notifications
You must be signed in to change notification settings - Fork 215
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
json-to-dhall #878
Comments
Does |
@Profpatsch json-to-dhall Bool <<< 'true' | dhall-to-json
json-to-dhall Bool <<< 'false' | dhall-to-json
json-to-dhall Integer <<< 2 | dhall-to-json
json-to-dhall Natural <<< 2 | dhall-to-json
json-to-dhall Double <<< -2.345 | dhall-to-json
json-to-dhall Text <<< '"foo bar"' | dhall-to-json
json-to-dhall 'List Integer' <<< '[1, 2, 3]' | dhall-to-json
json-to-dhall '{foo : List Integer}' <<< '{"foo": [1, 2, 3]}' | dhall-to-json
json-to-dhall '{foo : List Integer}' <<< '{"foo": [1, 2, 3], "bar" : "asdf"}' | dhall-to-json
json-to-dhall '{ a : Integer, b : Text }' <<< '[{"key":"a", "value":1}, {"key":"b", "value":"asdf"}]' | dhall-to-json
json-to-dhall 'List { mapKey : Text, mapValue : Text }' <<< '{"foo": "bar"}' | dhall-to-json
json-to-dhall "Optional Integer" <<< '1' | dhall-to-json
json-to-dhall '{ a : Integer, b : Optional Text }' <<< '{ "a": 1 }' | dhall-to-json
json-to-dhall 'List < Left : Text | Right : Integer >' <<< '[1, "bar"]' | dhall-to-json
json-to-dhall '{foo : < Left : Text | Right : Integer >}' <<< '{ "foo": "bar" }' | dhall-to-json
json-to-dhall '{foo : < Left : Text | Middle : Text | Right : Integer >}' <<< '{ "foo": "bar"}' | dhall-to-json
|
As long as the round-trip works it’s fine I guess. |
Indeed! Also, you generally cannot derive There are also situations where you would prefer to interpret/import a JSON object as a key-value association list rather than a Dhall record (for example, So |
This is great! I think the main thing we need is to upstream this into the standard, mainly to sort out corner cases (like how to handle unions, if at all), to document the expected behavior, and to give other implementations input into how JSON support evolves. |
@Gabriel439 I agree, the JSON interface needs to be standardized. The proper JSON importing functionality could increase Dhall usefulness and adoption significantly. Currently, in Back to your suggestion, where should this upstream to more exactly (I am not yet very familiar with the project hierarchy). Is there a specific file or folder in |
@Gabriel439 Regarding the corner cases, I added the following options/flags for importing
With regards to the JSON key-value lists are imported as Are there other important corner cases to consider? What did I miss? |
Are you suggesting we standardize before merging this PR (and releasing the program) or are you saying we standardize as an auxiliary thing to do? I ask because as @antislava hinted to:
There's no standardization for going the other way. And, printing seems way more important than parsing. I'm all for standardization of JSON decoding/encoding. I don't think it's that big a burden to add, either. This isn't me fighting against standardizing. It's just a little unclear why we need it now before adding a program to a separate repo. |
I agree with @joneshf that standardization should be an independent process from just merging this - we can always standardize the other way around (i.e. from here to the standard), as it happened with the main implementation. I'll also add that I think implementing a JSON interface should not be compulsory for a given implementation (the usual reason is to lighten the implementation-bootstrapping process, as this feels a bit orthogonal) |
@antislava: I originally envisioned first upstreaming this into the standard, but I've changed my mind and think it's worth merging this even before we standardize it. If you open the pull request I'll accept it |
Done! #884 Note that I was getting some unrelated Dhall test failures after merging the latest master into my branch, so I had to disable tests in ps @Gabriel439 I keep seeing minor errors in Hydra builds (most recently, related to pps ah, I see it was |
For interest's sake: there are also experimental |
@singpolyma Thank you for the info! Could you please link to some list of simple examples of how it works in your repository? (Do you also require some sort of a schema as an input argument?) |
@singpolyma Thank you for the info! Could you please link to some list of simple examples of how it works? (Do you also provide any sort of a schema as an input argument?)
No schema. You run it like:
bundle exec json-to-dhall < path/to.json | dhall decode
(it emits binary encoded dhall, so if you want souce use dhall decode command).
Basic types (number, string) do what you expect. Homogenous array does what you expect. Almost-homogenous array with nulls generates list of optionals. Heterogenous array generates list of union. Map becomes record. Map keys that are null are omitted from the output.
|
I'll mark this resolved now that #884 is merged |
Implemented a simple
json-to-dhall
tool: master...antislava:antislava/json-to-dhall.Haddock documentation following the structure of
dhall-to-json
is a bit rough but reasonably complete in Main.hs (cabal new-haddock exe:json-to-dhall
works indhall-json
'snix-shell
).The conversion function is relatively straightforward but I had to put some thought into what the default behavior should be (in particular with regards to unions and records).
So far tested it only on simple cases (listed in the documentation). For a more "real-life" example, check out bower.dhall.
Related discussions:
The text was updated successfully, but these errors were encountered: