rjg

Crates.iorjg
lib.rsrjg
version0.4.1
created_at2024-09-13 02:05:15.748712+00
updated_at2026-01-10 07:44:09.023014+00
descriptionRandom JSON Generator
homepagehttps://github.com/sile/rjg
repositoryhttps://github.com/sile/rjg
max_upload_size
id1373277
size21,604
Takeru Ohta (sile)

documentation

README

rjg

rjg Actions Status License

Random JSON Generator.

rjg reads a JSON template from stdin and generates random JSON values based on embedded generator patterns.

// Install
$ cargo install rjg

// Generate integer arrays
$ echo '[0, "$u4", 9]' | rjg --count 3
[0,8,9]
[0,6,9]
[0,5,9]

// Generate objects
$ echo '{"put": {"key": "$s[3]", "value": {"$oneof": [null, "$u16"]}}}' | rjg --count 3
{"put":{"key":"cic","value":63308}}
{"put":{"key":"b36","value":10142}}
{"put":{"key":"9dj","value":null}}

// Print help.
$ rjg -h
Random JSON Generator

Usage: rjg [OPTIONS]

Options:
  -h, --help            Print help ('--help' for full help, '-h' for summary)
      --version         Print version
  -c, --count <INTEGER> Number of JSON values to generate [default: 1]
  -s, --seed <INTEGER>  Seed for the random number generator

Rules

  • Input templates can use JSONC format (JSON with comments), but the output is always plain JSON
  • Literal JSON values in a template are output exactly as written
  • The following patterns are treated as generators and will produce random values:
    • Strings beginning with $ (e.g., "$u8", "$i32", "$s[5]", "$seqno")
    • Objects with a single $oneof key
  • Generators produce output as follows:
    • "$seqno": Generates a sequence number starting from 0 and incrementing by 1 for each occurrence of $seqno during generation (even within a single JSON value)
    • "$u<bits>": Generates a random unsigned integer with the specified bit width (e.g., "$u8", "$u16"; 1-64 bits)
    • "$i<bits>": Generates a random signed integer with the specified bit width (e.g., "$i8", "$i32"; 1-64 bits)
    • "$s[<length>]": Generates a random alphanumeric string of the specified length (e.g., "$s[5]"; minimum 1 character)
    • {"$oneof": [VALUE, ...]}: Randomly selects and outputs one value from the provided array
Commit count: 114

cargo fmt