Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upDiscussion: Support for importing from JSON #121
Comments
Gabriel439
referenced this issue
Mar 20, 2018
Closed
Other direction in interoperability with JSON/YAML? #326
This comment has been minimized.
This comment has been minimized.
aleator
commented
Mar 27, 2018
|
My humble opinion about this is that Dhall should always require a type annotation, regardless of how 'guessable' the imported type is. The rationale is that even though your list stores only ints now it may end up with booleans later and it feels inappropriate to implicitly guess when importing files. Better would be to make Also, I think that only implicit conversion that is sensible is to equate null & missing values to optional. |
This comment has been minimized.
This comment has been minimized.
|
I don’t think the idea is to guess types. From #326: ./foo.json as JSON : List { name : Text, age : Natural } |
This comment has been minimized.
This comment has been minimized.
aleator
commented
Mar 27, 2018
•
|
Well, since outlined options above are "reject" and "accept with type annotation" I thought that there would be a form where type annotation wasn't necessary ie. type would arise from imported data. Sorry about my confusion. |
This comment has been minimized.
This comment has been minimized.
|
I think the last section was about how JSON should be typed in dhall by default (yet still with deterministic rules what gets which type). For example the aforementioned
would accept
could accept the latter and would type it as @Gabriel439 I personally think dynamically adding optionals would only make sense if Dhall can infer the needed fields from usage, which it can’t. Since everywhere else types are not optional (and can’t be inferred) I think this would break consistency (and maybe bring up the expectation that it infers from usage). |
This comment has been minimized.
This comment has been minimized.
|
Yeah, my personal preference is for a mandatory type signature, too. I just didn't want to bias the discussion at the very beginning. My reasoning is that it would be very weird for this: [ 1 ]... to have an inferred type of [ 1, null ]... has an inferred type of However, there is still the question of whether or not Dhall should allow importing this JSON: [ 1, true ]... using a type annotation with a sum type like this: ./foo.json as JSON : List < Left : Integer, Right : Bool >The main downside of that proposal that I'm aware of is that you have to specify what happens if you start nesting sum types or if you have sum types with multiple constructors that wrap the same type. My inclination is to still reject that, but I just wanted to mention it because
|
This comment has been minimized.
This comment has been minimized.
aleator
commented
Mar 27, 2018
|
Well, I was referring to "typed by default" as guessing. I think there are two use cases for dhall-from-json:
As a final thought, how about adding import plugins (using similar scheme as in pandoc) to dhall? You would supply dhall with a program/script that can output dhall expressions and then import other bits of data through that script. For example, you could do something like:
This would allow testing different JSON import schemes or interacting with other more task specific data sources. Successful data providing plugins could be merged to dhall after they've seen some real world use. (This could also handle things like dhall-lang/dhall-haskell#292) |
This comment has been minimized.
This comment has been minimized.
|
Yeah, I like the plugin idea, although I would prefer to do it through the Haskell API instead of the command line |
This comment has been minimized.
This comment has been minimized.
|
Untagged unions should be different from sum types in my opinion. I wouldn’t have expected |
This comment has been minimized.
This comment has been minimized.
aleator
commented
Mar 28, 2018
|
Command line vs. Haskell API depends on who you wish to write plugins. I would guess that today most dhall is consumed by Haskell programs and the plugin is easiest and safest to add there. However, if you use dhall from command line a lot then you'll need to build your own binary. Not a problem for Haskell users but probably a bit of a hurdle for the rest. |
This comment has been minimized.
This comment has been minimized.
|
Keep in mind that the long term goal of Dhall is language bindings other than Haskell. So ideally there would be a language binding in that user's preferred language that they could use to customize the import resolution behavior. The main reason I want to avoid a plugin API is that then I have to standardize the semantics and interface for plugins and every Dhall implementation would need to support that standard plugin semantics. Note that in the long run I don't want users to have to use any binaries at all. The integration with their preferred language should be through a library rather than a subprocess call to some In other words: I agree with the goal that users shouldn't have to build their own binaries, but I believe that the correct solution to that goal is to finish standardizing import semantics in order to create more language bindings rather than make the binaries of one implementation hyper-customizable. |
This comment has been minimized.
This comment has been minimized.
aleator
commented
Apr 12, 2018
•
|
I met an another case where having some kind of extended importing would be useful. I'm using dhall to describe some course exercises. Now, some exercises are in want of bibliography links and all I have is a large bibtex file. In this case I converted the bibliography, partly and by hand, into dhall so I could import the required entries. It would've been nice if I could've imported the .bib file directly. Doing the bib->dhall conversion means that the .bib file is no longer the primary data source and that I need to write a converter from dhall to bib to make use of the entries that I converted into dhall. Perhaps extending the syntax so that |
This comment has been minimized.
This comment has been minimized.
marcb
commented
Sep 30, 2018
|
I've been pondering this for a little while and I feel that The tool could also possibly take two corpus' that reflect both valid and error JSON responses so allow for a union type to cover both circumstances... |
Gabriel439
referenced this issue
Oct 17, 2018
Open
Dealing with assoc lists / maps is annoying. #234
This comment has been minimized.
This comment has been minimized.
madjar
commented
Nov 30, 2018
•
|
I've spent the afternoon making a toy json-to-dhall tool (https://gist.github.com/madjar/252c517644c0e13ef28a2a7ca71f5fa4). It's very prototypey code, and just supports most basic types, as well as optionals and dynamic maps (mapKey/mapValue). The question is: if I want to transform this into something that's actually useful, where should it live:
|
This comment has been minimized.
This comment has been minimized.
|
@madjar: We want to add this to the language standard and once it's there then it will live in all implementations of the standard using the The key thing to emphasize is that the standardization process and agreeing upon the desired behavior is the bottleneck here because once it is standardized then I expect it will be pretty straightforward to update the implementation to match. |
This comment has been minimized.
This comment has been minimized.
madjar
commented
Nov 30, 2018
|
@Gabriel439 If your review it closely, then I'll have to apologize for the quality. It was kind of rushed this afternoon. The approach I've take is the one describe in dhall-lang/dhall-json#23 (comment), under "Convert and type check together", which is to recursively traverse both the json Having this tool made the conversion of a json file and the definition of its dhall type quite nice, allowing to incrementally add the missing parts to the type definition while having quick feedback. But I understand that you see this not as tooling, but as part of the language, thus requiring more standardization than "whatever the tool does". I'll familiarize myself with the processes of the project, then. Thanks! |
f-f
referenced this issue
Jan 18, 2019
Open
Discussion: transpile dhall to other languages in both directions? #346
sarneaud
referenced this issue
Mar 4, 2019
Closed
Could the documentation be more specific about what a "malicious user" is? #333
Gabriel439
referenced this issue
Mar 18, 2019
Open
Embedding arbitrary structures into Dhall values #435
This comment has been minimized.
This comment has been minimized.
|
My opinion on this is that this would be extremely cool. |
This comment has been minimized.
This comment has been minimized.
ari-becker
commented
Apr 8, 2019
•
|
I agree that a With that said, I don't think that the type inputs for Consider, for instance, the dhall-terraform-output script which takes Terraform's JSON output and assembles both a type and a record from that output. Because the record keys are variable, it's not possible to define a Dhall type for arbitrary Terraform JSON output ahead of time (or rather, it is, but it would be fragile). However, this doesn't mean that Terraform's JSON output doesn't follow a predictable pattern, and ideally, upon parsing Terraform's JSON output, it would be best to verify that the JSON output fits that pattern, and possibly even get a type that fit the predicted pattern. What's the best way to do that? I don't know. Maybe, instead of Probably it would be best to start with |
This comment has been minimized.
This comment has been minimized.
alexanderkjeldaas
commented
Apr 24, 2019
|
I think requiring type annotations will make it mostly impossible to import large JSON structures like CloudFormation data. |
This comment has been minimized.
This comment has been minimized.
|
@alexanderkjeldaas: Wouldn't they also fail to import without type annotations? Usually those kinds of JSON files mix records of various types |
This comment has been minimized.
This comment has been minimized.
antislava
commented
Apr 24, 2019
|
@alexanderkjeldaas : Please, try the (new) |
Gabriel439 commentedMar 20, 2018
One pretty heavily requested feature is importing JSON values directly into Dhall. The most common requested reasons for doing this are:
I'm open to the idea although I probably won't implement it until the import semantics are standardized (any day now :) ). In the meantime, though, I can still gather feedback on whether Dhall should support this feature and to flesh out what it might look like if it were proposed.
This would most likely be similar in spirit to Dhall's existing support for importing raw text using
as Text. In other words, you would be able to write./foo.json as JSONto import a JSON file into Dhall), however there are still some open issues that need to be resolved.For those who are in favor of this feature, the easiest way to drive this discussion is to discuss how Dhall should behave when importing the following JSON expressions which cover most of the corner cases that I'm aware of:
[ { "x": 1 }, { "x":1, "y":true } ]For each of these imports, should Dhall:
Optionaltype)?