diff --git a/dhall-json/CHANGELOG.md b/dhall-json/CHANGELOG.md index d687178..8939738 100644 --- a/dhall-json/CHANGELOG.md +++ b/dhall-json/CHANGELOG.md @@ -1,3 +1,7 @@ +Next version + +* [BREAKING CHANGE: Enable `--pretty` by default for `dhall-to-json`](https://github.com/dhall-lang/dhall-haskell/issues/716) + 1.4.1 * [Enable `--records-strict` by default for `{json-yaml}-to-dhall`](https://github.com/dhall-lang/dhall-haskell/pull/1181) diff --git a/dhall-json/dhall-to-json/Main.hs b/dhall-json/dhall-to-json/Main.hs index 0309ea5..86727ad 100644 --- a/dhall-json/dhall-to-json/Main.hs +++ b/dhall-json/dhall-to-json/Main.hs @@ -62,7 +62,7 @@ parseOptions = Options.flag' True ( Options.long "pretty" - <> Options.help "Pretty print generated JSON" + <> Options.help "Deprecated, will be removed soon. Pretty print generated JSON" ) compactFlag = @@ -73,7 +73,7 @@ parseOptions = ) defaultBehavior = - pure False + pure True parseVersion = Options.flag' diff --git a/dhall-json/src/Dhall/JSON.hs b/dhall-json/src/Dhall/JSON.hs index 4b002c5..aec4a45 100644 --- a/dhall-json/src/Dhall/JSON.hs +++ b/dhall-json/src/Dhall/JSON.hs @@ -56,7 +56,11 @@ Dhall @List@s translate to JSON lists: > $ dhall-to-json <<< '[1, 2, 3] : List Natural' -> [1,2,3] +> [ +> 1, +> 2, +> 3 +> ] Dhall @Optional@ values translate to @null@ if absent and the unwrapped value otherwise: @@ -69,7 +73,10 @@ Dhall records translate to JSON records: > $ dhall-to-json <<< '{ foo = 1, bar = True }' -> {"foo":1,"bar":true} +> { +> "bar": true, +> "foo": 1 +> } Dhall unions translate to the wrapped value: @@ -85,7 +92,22 @@ > , MyType.Person { age = 35, name = "Alice" } > ] > $ dhall-to-json <<< "./config" -> [{"age":47,"name":"John"},{"location":"North Pole"},{"location":"Sahara Desert"},{"age":35,"name":"Alice"}] +> [ +> { +> "age": 47, +> "name": "John" +> }, +> { +> "location": "North Pole" +> }, +> { +> "location": "Sahara Desert" +> }, +> { +> "age": 35, +> "name": "Alice" +> } +> ] You can preserve the name of the alternative if you wrap the value in a record with three fields: @@ -154,7 +176,13 @@ > ] > $ dhall-to-json <<< './example.dhall' -> {"foo":null,"bar":[1,true]} +> { +> "bar": [ +> 1, +> true +> ], +> "foo": null +> } Also, all Dhall expressions are normalized before translation to JSON: