I have to create a Random Json to fill a column of a sql table. For this I need to create a function to create a random Json in Java which will be passed the number of fields, nestedness of the JSON(for now assuming 1 for simplicity), key and value type.
Eg:- I want to generate and return this from that function :-
{
"abcd" : "wedcevef",
"bshe" : "eyguhcve",
"uehv" : "dchbjvnn",
"ecue" : "gchbccwg",
}
For the above example the number of feilds=4, nestedness=1, keyType= string(4) , valueType=string(8).
For making the random JSON key and values I already have a function :-
public String astring(int minimum_length, int maximum_length) {
return randomString(minimum_length, maximum_length, 'a', 26);
}
private String randomString(int minimum_length, int maximum_length, char base, int numCharacters) {
int length = number(minimum_length, maximum_length);
byte baseByte = (byte) base;
byte[] bytes = new byte[length];
for (int i = 0; i < length; ++i) {
bytes[i] = (byte) (baseByte + number(0, numCharacters - 1));
}
return new String(bytes);
}
How should I design this function? keeping in mind the nestedness will increase later on?