A commandline tool to generate static or random JSON records
Find a file
Mathias Fussenegger 76282aadb7
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
Run doctests via cabal doctest or cabal repl --with-compiler=doctest
2025-09-14 20:04:30 +02:00
.github Bump stack resolver to lts-24.0 2025-07-19 23:17:16 +02:00
app Simplify arg parsing 2025-09-14 19:23:49 +02:00
benchmarks Add a benchmark for fromRegex 2021-05-13 15:47:49 +02:00
src Simplify arg parsing 2025-09-14 19:23:49 +02:00
tests Run doctests via cabal doctest or cabal repl --with-compiler=doctest 2025-09-14 20:04:30 +02:00
.gitignore Use cabal file directly instead of via hpack 2020-04-27 21:12:22 +02:00
.woodpecker.yaml Run doctests via cabal doctest or cabal repl --with-compiler=doctest 2025-09-14 20:04:30 +02:00
ChangeLog.md Release 0.4.0 2024-04-18 15:12:14 +02:00
LICENSE Initial commit 2018-11-28 21:46:12 +01:00
mkjson.cabal Run doctests via cabal doctest or cabal repl --with-compiler=doctest 2025-09-14 20:04:30 +02:00
README.md Bump stack resolver to lts-24.0 2025-07-19 23:17:16 +02:00
Setup.hs Initial commit 2018-11-28 21:46:12 +01:00
stack.yaml Bump stack resolver to lts-24.0 2025-07-19 23:17:16 +02:00
stack.yaml.lock Bump stack resolver to lts-24.0 2025-07-19 23:17:16 +02:00

mkjson

mkjson is a CLI to generate JSON records.

Static JSON:

↪  mkjson x=10 y=20 foo=bar
{"foo":"bar","x":10,"y":20}

Generated random data:

↪  mkjson --num 3 id="uuid4()" x="randomInt(0, 10)"
{"id":"2c6ce42f-5f7d-4e65-a1a1-8b39f6cfce19","x":6}
{"id":"d4c1af69-3cdd-417d-98e0-d3774f5fa1be","x":8}
{"id":"8fc064c9-57ba-4d78-b205-57899776e757","x":6}

It takes fieldName=value or fieldName=provider() pairs as argument. Each pair will result in a field within the JSON object.

To generate infinite records, use:

↪  mkjson --num Inf

Examples

Using fromFile and oneOf:

↪  mkjson --num 3 w="oneOf(fromFile('/usr/share/dict/words'))"
{"w":"Karl"}
{"w":"demographic"}
{"w":"calumny's"}

Use dotted notation to create objects:

↪  mkjson point.x=10 point.y=20
{"point":{"x":10,"y":20}}

Or nest calls to create objects:

↪  mkjson obj=$(mkjson xs="array(randomInt(0, 4), randomInt(5, 9))")
{"obj":{"xs":[2,5]}}

Or use the object provider with various providers. Argument are key, value [, ...] pairs:

↪  mkjson obj="object(dt, randomDateTime(), type, fromRegex('[a-z]{4}-\d+'), xs, replicate(5, randomInt(0, 10)))"
{"obj":{"dt":"2099-09-11T16:33:41Z","xs":[6,8,5,2,0],"type":"ldwa-2667786160"}}

You may also want to read this introduction and sample use case.

Available providers

  • uuid1
  • uuid4
  • null
  • randomBool
  • randomChar
  • randomInt(lower, upper)
  • randomDouble(lower, upper)
  • randomDate [(lower, upper)]
  • randomDateTime [(lower, upper)]
  • array(expr [, ...])
  • oneOf(arrayExpr)
  • oneOf(expr, expr [, ...])
  • replicate(number, expr)
  • object(key, value [, ...])
  • fromFile(fileName)
  • fromRegex(pattern)
  • join(sep, val1, [, ...])
  • join(array)

Installation

Get a pre-build binary from the releases page or build it yourself:

Install stack:

curl -sSL https://get.haskellstack.org/ | sh

Install mkjson:

git clone https://github.com/mfussenegger/mkjson.git
cd mkjson
stack install

Alternatives

There are some alternatives if you're not so interested in the random-value generation aspect of mkjson: