-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Compile Dhall to JSON or YAML -- -- Use this package if you want to compile Dhall expressions to JSON or -- YAML. You can use this package as a library or an executable: -- --
Text
-- $ dhall-to-json <<< 'True' -- true -- $ dhall-to-json <<< 'False' -- false ---- -- Dhall numbers translate to JSON numbers: -- --
-- $ dhall-to-json <<< '+2' -- 2 -- $ dhall-to-json <<< '2' -- 2 -- $ dhall-to-json <<< '2.3' -- 2.3 ---- -- Dhall Text translates to JSON text: -- --
-- $ dhall-to-json <<< '"ABC"' -- "ABC" ---- -- Dhall Lists translate to JSON lists: -- --
-- $ dhall-to-json <<< '[1, 2, 3] : List Integer' -- [1,2,3] ---- -- Dhall Optional values translate to null if absent -- and the unwrapped value otherwise: -- --
-- $ dhall-to-json <<< '[] : Optional Integer' -- null -- $ dhall-to-json <<< '[1] : Optional Integer' -- 1 ---- -- Dhall records translate to JSON records: -- --
-- $ dhall-to-json <<< '{ foo = 1, bar = True }'
-- {"foo":1,"bar":true}
--
--
-- Dhall unions translate to the wrapped value:
--
--
-- $ dhall-to-json <<< "< Left = +2 | Right : Natural>"
-- 2
-- $ cat config
-- [ < Person = { age = +47, name = "John" }
-- | Place : { location : Text }
-- >
-- , < Place = { location = "North Pole" }
-- | Person : { age : Natural, name : Text }
-- >
-- , < Place = { location = "Sahara Desert" }
-- | Person : { age : Natural, name : Text }
-- >
-- , < Person = { age = +35, name = "Alice" }
-- | Place : { location : Text }
-- >
-- ]
-- $ dhall-to-json <<< "./config"
-- [{"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:
--
--
-- let Example = < Left : { foo : Natural } | Right : { bar : Bool } >
--
-- in let example = constructors Example
--
-- in let Nesting = < Inline : {} | Nested : Text >
--
-- in let nesting = constructors Nesting
--
-- in { field = "name"
-- , nesting = nesting.Inline {=}
-- , contents = example.Left { foo = 2 }
-- }
--
--
-- ... produces this JSON:
--
--
-- {
-- "foo": 2,
-- "name": "Left"
-- }
--
--
-- If nesting is set to Nested nestedField then the
-- union is store underneath a field named nestedField. For
-- example, this code:
--
--
-- let Example = < Left : { foo : Natural } | Right : { bar : Bool } >
--
-- in let example = constructors Example
--
-- in let Nesting = < Inline : {} | Nested : Text >
--
-- in let nesting = constructors Nesting
--
-- in { field = "name"
-- , nesting = nesting.Nested "value"
-- , contents = example.Left { foo = 2 }
-- }
--
--
-- ... produces this JSON:
--
--
-- {
-- "name": "Left",
-- "value": {
-- "foo": 2
-- }
-- }
--
--
-- Also, all Dhall expressions are normalized before translation to JSON:
--
-- -- $ dhall-to-json <<< "True == False" -- false --module Dhall.JSON -- | Convert a Dhall expression to the equivalent JSON expression -- --
-- >>> :set -XOverloadedStrings
--
-- >>> :set -XOverloadedLists
--
-- >>> import Dhall.Core
--
-- >>> dhallToJSON (RecordLit [("foo", IntegerLit 1), ("bar", TextLit "ABC")])
-- Right (Object (fromList [("foo",Number 1.0),("bar",String "ABC")]))
--
-- >>> fmap Data.Aeson.encode it
-- Right "{\"foo\":1,\"bar\":\"ABC\"}"
--
dhallToJSON :: Expr s X -> Either CompileError Value
-- | Omit record fields that are null
omitNull :: Value -> Value
-- | Specify whether or not to convert association lists of type List {
-- mapKey: Text, mapValue : v } to records
data Conversion
NoConversion :: Conversion
Conversion :: Text -> Text -> Conversion
[mapKey] :: Conversion -> Text
[mapValue] :: Conversion -> Text
-- | Convert association lists to homogeneous maps
--
-- This converts an association list of the form:
--
--
-- [ { mapKey = k0, mapValue = v0 }, { mapKey = k1, mapValue = v1 } ]
--
--
-- ... to a record of the form:
--
--
-- { k0 = v0, k1 = v1 }
--
convertToHomogeneousMaps :: Conversion -> Expr s X -> Expr s X
parseConversion :: Parser Conversion
-- | Convert a piece of Text carrying a Dhall inscription to an equivalent
-- JSON Value
--
--
-- >>> :set -XOverloadedStrings
--
-- >>> import Dhall.Core
--
-- >>> Dhall.JSON.codeToValue "(stdin)" "{ a = 1 }"
--
-- >>> Object (fromList [("a",Number 1.0)])
--
codeToValue :: Conversion -> Text -> Text -> IO Value
-- | This is the exception type for errors that might arise when
-- translating Dhall to JSON
--
-- Because the majority of Dhall language features do not translate to
-- JSON this just returns the expression that failed
data CompileError
Unsupported :: (Expr X X) -> CompileError
instance GHC.Show.Show Dhall.JSON.CompileError
instance GHC.Exception.Exception Dhall.JSON.CompileError