json-directory: Load JSON from files in a directory structure

[ bsd3, codec, library, program ] [ Propose Tags ]

Load JSON from files in a directory structure. The object created mirrors the directory structure, using filenames as keys. Useful for breaking apart large JSON structures.


[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
Change log CHANGELOG.md
Dependencies aeson (>=2), base (>=4.11 && <5.0), bytestring, directory, filepath, json-directory, mtl, process, text, unordered-containers [details]
License BSD-3-Clause
Copyright (c) 2019 Luke Clifton
Author Luke Clifton
Maintainer lukec@themk.net
Category Codec
Bug tracker https://github.com/luke-clifton/json-directory/issues
Source repo head: git clone https://github.com/luke-clifton/json-directory
Uploaded by lukec at 2022-06-22T13:50:18Z
Distributions NixOS:0.1.0.2
Executables jsondir
Downloads 689 total (15 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 json-directory-0.1.0.2

[back to package description]

JSON Directory

Provides utilities for reading JSON structures out of directories. Directory entries become keys in a map, and the values are sourced from the contets of each entry.

By default

  • Directories are recured into
  • Files ending with .json are read as JSON values
  • Everything else is interpreted as a string

However, these can be modified with rules, that allow for interpreting any sort of file as JSON.

The example directory in this repository would result in the following JSON value.

{
  "empty": {},
  "a": "This is files will have its contents written into a JSON string.\n",
  "d": {
    "example": "Sometimes it's convenient to embed some raw JSON"
  },
  "b": 42,
  "c": {
    "nested": "You can nest directories to create a tree structure.\n"
  }
}

jsondir

This package also includes an executable for turning directories into JSON blobs.

jsondir [--help] [--rule <SUFFIX> <FILTER> ...]
        [--[no-]default{s,-json,-text}] <ROOT> ...

  Turn a directory structure into a JSON value

 --rule <SUFFIX> <FILTER>     Filter the contents of files with the given
                              SUFFIX with FILTER. The default rules use .json
                              files as is, and treat everything else as strings.
                              Can be specified multiple times. Rule are tried in
                              the order specified.
 --[no-]defaults              Enable or disable the default rules. Default on.
 --[no-]default-json          Enable or disable the .json file rule
 --[no-]default-text          Enable or disable the raw file to JSON string rule.
 <ROOT>                       Directory root to turn into a JSON value

 EXAMPLE
  jsondir --rule '.yml' yaml2json ./my-dir