All Projects → mangatmodi → Randomjson

mangatmodi / Randomjson

Licence: mit
Provides a Kotlin/Java library to create a random json string

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Randomjson

Pyjfuzz
PyJFuzz - Python JSON Fuzzer
Stars: ✭ 342 (+388.57%)
Mutual labels:  json, fuzzing
Snodge
Randomly mutate JSON, XML, HTML forms, text and binary data for fuzz testing
Stars: ✭ 121 (+72.86%)
Mutual labels:  json, fuzzing
Zzzjson
The fastest JSON parser written in pure C
Stars: ✭ 66 (-5.71%)
Mutual labels:  json
Utils
🛠 Lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.
Stars: ✭ 1,158 (+1554.29%)
Mutual labels:  json
Null
reasonable handling of nullable values
Stars: ✭ 1,148 (+1540%)
Mutual labels:  json
Mjextension
A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file.
Stars: ✭ 8,458 (+11982.86%)
Mutual labels:  json
Httpz
purely functional http client with scalaz.Free
Stars: ✭ 67 (-4.29%)
Mutual labels:  json
Json In Db
Oracle Database JSON Examples
Stars: ✭ 65 (-7.14%)
Mutual labels:  json
Fastjson
Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection
Stars: ✭ 1,164 (+1562.86%)
Mutual labels:  json
Cti Taxii Client
OASIS TC Open Repository: TAXII 2 Client Library Written in Python
Stars: ✭ 67 (-4.29%)
Mutual labels:  json
Servicestack.text
.NET's fastest JSON, JSV and CSV Text Serializers
Stars: ✭ 1,157 (+1552.86%)
Mutual labels:  json
Js Jsonq
A simple Javascript Library to Query over Json Data
Stars: ✭ 67 (-4.29%)
Mutual labels:  json
Schemasafe
A reasonably safe JSON Schema validator with draft-04/06/07/2019-09 support.
Stars: ✭ 67 (-4.29%)
Mutual labels:  json
Magento2 Import Export Sample Files
Default Magento 2 CE import / export CSV files & sample files for Firebear Improved Import / Export extension
Stars: ✭ 68 (-2.86%)
Mutual labels:  json
Startup Matrix
Startup Matrix exported to CSV, JSON, Markdown and HTML formats. Credits to original article by Eric Stromberg.
Stars: ✭ 66 (-5.71%)
Mutual labels:  json
Json Rules Engine
A rules engine expressed in JSON
Stars: ✭ 1,159 (+1555.71%)
Mutual labels:  json
Json Ditto
Declarative JSON-to-JSON mapper .. shape-shift JSON files with Ditto 👻
Stars: ✭ 66 (-5.71%)
Mutual labels:  json
Dictfier
Python library to convert/serialize class instances(Objects) both flat and nested into a dictionary data structure. It's very useful in converting Python Objects into JSON format
Stars: ✭ 67 (-4.29%)
Mutual labels:  json
Book
📖 Guides and tutorials on how to fuzz Rust code
Stars: ✭ 67 (-4.29%)
Mutual labels:  fuzzing
Jquery Jsontotable
This plugin can convert JSON data type to table for html. JSON is used primarily to transmit data between a server and web application, as an alternative to XML. In these reasons todays many applications use json data format for data transferring. And you need json to table converter for html display.
Stars: ✭ 69 (-1.43%)
Mutual labels:  json

RandomJson CodeFactor Build Status

Provides library to create a random json. Provides two implementation of json creation

SampleJsonCreator: Creates JSON string from a sample string.

SimpleJsonCreator: Creates JSON string by taking number of required keys.

Some important considerations:

  1. The random value generations could be customised by giving your own implementation.
  2. The default given implementation is thread-safe. That means random strings can be created in different threads
  3. The library create one string for each call to create(). It does not provides any concurrency or streaming. It totally depends on the developer on how one wants to use it.

Java Interoperational

The library can be used in Java 10+. See example.

Usage

Configuration

First we need to create configuration for the creator. This config specify, the random value generators for each of the primitive json type. The library includes some basic generator for each type.

val config =  RandomJsonConfig(
    RandomDouble.threadLocalRandom(),
    RandomInt.threadLocalRandom(),
    RandomString.charArray("eusbwopw".toCharArray(), 5),
    RandomBoolean.uniform(),
    RandomString.charArray("abcdefg".toCharArray(), 5)
    )

SampleJsonCreator

Creates JSON string similar to {"key1":{"key2":3}} in structure but keys and values have random values.

val jsonCreator = RandomJsonCreator
    .fromSampleString("""{"key1":{"key2":3}}""", config, KeepKeys.No)
    println(jsonCreator.create())            
    

Above prints

{"ggdb":{"faea":1279812142}}

Keep the same keys as the sample string The sample string creator can create json with same keys as the original json.

    val input = """{"key1":{"key2":3}}""".trimIndent()

    val jsonCreator = RandomJsonCreator
        .fromSampleString(input, config, KeepKeys.YES)
    println(jsonCreator.create())

Above prints

{"key1":{"key2":2083614805}}

See more examples.

SimpleJsonCreator

Creates JSON string similar 2ith 10 keys, the structure of the json is decided by RandomTypeSelector, which specify which which type of json field will be added next. SimpleJsonCreator does not support arrays or nested json.

val jsonCreator = RandomJsonCreator
    .fromNumberOfKeys(10,config, RandomTypeSelector.uniform())
    println(jsonCreator.create())            
    

Customize random value generators

In the example below DummyDoubleValue implements RandomDouble to give 2.0 as the double value. So all the JSON strings created by jsonCreator below will contain 2.0 as double value

class DummyDoubleValue:RandomDouble{
    override fun next() =  2.0
}
val config =  RandomJsonConfig(
    DummyDoubleValue(),
    RandomInt.threadLocalRandom(),
    RandomString.charArray("eusbwopw".toCharArray(), 5),
    RandomBoolean.uniform(),
    RandomString.charArray("abcdefg".toCharArray(), 5)
    )


val jsonCreator = RandomJsonCreator
    .fromNumberOfKeys(10,config, RandomTypeSelector.uniform())
    println(jsonCreator.create())            

Parallel creation of random strings

In the example below, we used kotlin's coroutines based async-await util to create 10 json strings in parallel.

val jsonCreator = RandomJsonCreator
    .fromNumberOfKeys(10,config, RandomTypeSelector.uniform())
            
val tasks =  (1..10).map {
    async {
          println(jsonCreator.create())
        }
    }
    
tasks.forEach{ it.await()}

Java example

        RandomJsonConfig config = new RandomJsonConfig(
                RandomDouble.threadLocalRandom(),
                RandomInt.threadLocalRandom(),
                RandomString.charArray("eusbwopw".toCharArray(), 5),
                RandomBoolean.uniform(),
                RandomString.charArray("abcdefg".toCharArray(), 5)
        );

        RandomJsonCreator creator = RandomJsonCreator.fromSampleString(
                "{\"q\":1}",
                config,
                KeepKeys.no()
        );

       System.out.println(creator.create())

Install

The library could be installed from maven central

Maven

<dependency>
    <groupId>com.github.mangatmodi</groupId>
    <artifactId>randomjson</artifactId>
    <version>2.1.2</version>
</dependency>

Gradle

compile group: 'com.github.mangatmodi', name: 'randomjson', version: '2.1.2'
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].