randjson

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2020 License: MIT Imports: 4 Imported by: 1 module, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

randjson

GoDoc

Make random JSON in Go

Usage

Get the package

go get github.com/tidwall/randjson

Make some random JSON using the default options and a maximum of 12 nested child elements.

js := randjson.Make(12, nil)  
println(string(js))

Outputs:

{
  "interlocal": true,
  "subterjacent": null,
  "unpalpitating": false,
  "semitruth": null,
  "democratical": "becher",
  "extrapoetical": null,
  "sympathetically": null,
  "townless": [true],
  "glisten": null,
  "unverifiedness": null,
  "polariscopy": {
    "ayacahuite": {
      "vertebrocostal": true,
      "Langhian": [false, 89.32, null],
      "bubo": "albe",
      "avoidless": "unconsolatory",
      "revitalize": true,
      "brassiness": true
    },
    "booksellerish": true,
    "unduplicable": 44.49,
    "overtopple": {
      "sclerometer": "reune",
      "unbelt": false,
      "personalia": {
        "epeirogenic": "epeirogenic"
      },
      "scutellated": "unfroward"
    },
    "muffishness": false,
    "preignition": [true, "ramus", null, false],
    "evangeliarium": null,
    "ardri": 24.53,
    "playfulness": null
  },
  "playfulness": {
    "mumper": [],
    "contriturate": "avoidless"
  }
}

Options

type Options struct {
	// Pretty formats and indents the random json. Default true
	Pretty bool
	// Spread is the number of unique words to use. Default 1,000
	Words int
	// Rand is the random number generator to use. Default global rng
	Rand *rand.Rand
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = &Options{
	Pretty: true,
	Words:  1000,
	Rand:   nil,
}

DefaultOptions for Make()

Functions

func Append

func Append(dst []byte, depth int, opts *Options) []byte

Append a random json document to dst. The depth param is the maximum nested depth of json document

func Make

func Make(depth int, opts *Options) []byte

Make returns a random json document. The depth param is the maximum nested depth of json document

Types

type Options

type Options struct {
	// Pretty formats and indents the random json. Default true
	Pretty bool
	// Spread is the number of unique words to use. Default 1,000
	Words int
	// Rand is the random number generator to use. Default global rng
	Rand *rand.Rand
}

Options for Make()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址