e9571-config-reader-haskell: Automatically read config.json from the current directory

[ configuration, library, mit, program ] [ Propose Tags ] [ Report a vulnerability ]

Automatically discover and parse a config.json file in the current working directory or any of its parent directories. No need to manually pass file paths. Built on top of aeson, it provides a simple `getConfig :: FromJSON a => IO a` function that also supports default values when fields are missing in the JSON file.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2
Dependencies aeson (>=2.0 && <2.3), base (>=4.14 && <5), bytestring (>=0.10 && <0.13), directory (>=1.3 && <1.4), e9571-config-reader-haskell [details]
License MIT
Author e9571
Maintainer 95714623@qq.com
Category Configuration
Home page https://github.com/e9571/e9571-config-reader-haskell
Uploaded by e9571 at 2025-11-26T01:27:22Z
Distributions
Executables simple-example
Downloads 0 total (0 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for e9571-config-reader-haskell-0.1.0.2

[back to package description]

e9571-config-reader-haskell

A tiny, zero-configuration Haskell library that instantly reads a config.json file from the current working directory.

Out-of-the-box, no setup required.
Just drop a config.json file next to your executable and start using the library — it just works.

Usage (two steps)

  1. Create a config.json file in the same directory as your program:

    {
      "host": "127.0.0.1",
      "port": 8080
    }
    
  2.    {-# LANGUAGE OverloadedStrings #-}
       
       import E9571.ConfigReader
       import Data.Aeson
       
       data Config = Config { host :: String, port :: Int } deriving Show
       
       instance FromJSON Config where
           parseJSON = withObject "Config" $ \o -> Config
               <$> o .: "host"
               <*> o .: "port"
       
       main :: IO ()
       main = do
           cfg <- loadConfigOrDie :: IO Config   -- automatically reads ./config.json
           putStrLn $ "Server starting at " ++ host cfg ++ ":" ++ show (port cfg)
       
           
    
    
    
    
    

Features

  • Automatically looks for ./config.json at runtime
  • No file paths, no command-line flags, no environment variables
  • Works with any FromJSON instance
  • Helpful error messages when the file is missing or malformed
  • Only depends on aeson

Installation

cabal install e9571-config-reader-haskell

Source: https://github.com/e9571/e9571-config-reader-haskell Hackage: https://hackage.haskell.org/package/e9571-config-reader-haskell

Enjoy the simplicity!