skip to Main Content

Dhall is famous for generating JSON, namely from input.dhall to output.json. Is it possible to write a “JSON transformer” in Dhall, namely “input.json + rules.dhalloutput.json”? It still sounds functional (two input and one output), but I wonder whether Dhall is the right tool for this purpose. I know how to import the JSON file as bytes, but I hear that Dhall intentionally avoids supporting any text parsing.

2

Answers


  1. Chosen as BEST ANSWER

    Instead of parsing JSON in Dhall, I guess the idiomatic way is to generate Dhall code from the JSON, which can be done by the json-to-dhall utility from the dhall-json package. Let’s call the generated file generated.dhall. After that, we can create result.dhall with

    let original = ./generated.dhall
    in original ⫽ { someKey = "new value" }
    

    Then we can convert the data back to JSON with dhall-to-json.


  2. Currently Dhall does not support a way to import JSON expressions at runtime. You can only conver them to Dhall using the json-to-dhall utility.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search