Package: ranjg
ranjg 0.5.0.x — Randomly json generatorranjgis a package providing functions to generate random JSON data according to JSON-Schema-LIKEobject. (It is similar to JSON schema, but does NOT support some keywords. Also seehere.)This package can be used on command line and python code.Quick Start (on command line)Install the package with the following command. (Same to usage in python code)pipinstallranjgMake a schema file. For example (schema.json):{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":32},"age":{"type":"integer","minimum":0},"comment":{"type":"string","minLength":1}},"required":["name","age"]}Execute the package on command line with following command:python-mranjg./schema.jsonThen generated json string will be outputted.It generates JSONrandomly. So you will get a different result each time you execute it.Quick Start (in python code)Install the package with the following command. (Same to usage on command line)pipinstallranjgMake a python file. For example (generate.py):importranjgschema={'type':'object','properties':{'name':{'type':'string','minLength':1,'maxLength':32},'age':{'type':'integer','minimum':0},'comment':{'type':'string','minLength':1}},'required':['name','age']}generated=ranjg.gen(schema)print(generated)Execute the python code with following command:pythongenerate.pyThen generated json string will be outputted.It generates JSONrandomly. So you will get a different result each time you execute it.Document (command line usage)You can execute ranjg with below command:python-mranjg<schema_file_path>[-j<json_output_path>[-n<num>]][--options<options_file>][--list<multiplicity>]This command generates a JSON string. Each argument has the following meaning:<schema_file_path>: A file path of the JSON-schema-like file. Generated JSON string will be according to this schema. (What's "JSON-schema-like"?)-j <json_output_path>(optional): When it's specified, a generated JSON string will be written to the specified file. When it's not specified, a generated JSON string will be written to stdout.--options <options_file>(optional): It can be specified to use Options. See alsoOptions.--list <multiplicity>(optional): When it's specified, a list of lengthmultiplicityis generated. Each element of the generated list specifies the schema.-n <num>(optional): When it's specified, it repeats the generationnumtimes and output each result to a different file. If you use this option,json_output_pathmust have placeholder such as{}.Document (python code usage)Usually, the following function is used:defgen(schema:dict=None,schema_file:str=None,output_file:str=None,output_fp=None,options:Options=None,options_file:str=None)->strThis function returns a generated JSON string.Eitherschemaorschema_filemust be specified (generated JSON string is according to them).schemais a JSON-schema-like dict andschema_fileis the path to a JSON-schema-like file. (What's "JSON-schema-like"?)Whenoutput_fileis specified, the generated JSON string will be written to the file of the specified path. Whenoutput_fpis specified with a file object opened in write mode, the result will be written to the specified file. You cannot specifyoutput_fileandoutput_fpin the same function call.optionsoroptions_filecan be specified to use Options. See alsoOptions.Supported keywords of schemaThis package generates JSON string according to JSON-schema-LIKEobject.JSON-schema-LIKE objectis like general JSON schema, but it doesN'T SUPPORT some keywords of general JSON schema.The following keywords can be used in much the same way as in regular JSON schema. (If you want to know the effect of each keyword, please readJSON Schema Reference.)Supported keywords"type"Allowed: "object", "array", "string", "number", "integer", "boolean", "null" and multiple type."properties", "required""items", "minItems", "maxItems", "additionalItems""pattern", "minLength", "maxLength"Warning: When "pattern" specified, "minLength" and "maxLength" are ignored."minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum""enum"OptionsOptions allow you to specify generation rules that are not specified in the schema.See alsoOptions.