You can use mockneat in order to do that. It's a library specialised in generating all kind of "fake" data. Check out the documentation to see what you can "fake" and how.
There is a wiki page that shows you how you can generate a Random JSON:
MockNeat mockNeat = MockNeat.threadLocal();
Gson gson = new GsonBuilder()
.setPrettyPrinting()
.create();
String json = mockNeat
.reflect(UserProfile.class)
.field("name", mockNeat.names().full())
.field("userName", mockNeat.users())
.field("email", mockNeat.emails())
.field("profiles",
mockNeat.reflect(Profile.class)
.field("profileId", mockNeat.ints().range(100, 1000))
.field("profileAdded", mockNeat.localDates().toUtilDate())
.list(2))
.map(gson::toJson) /* Transforms the UserProfile class into a 'pretty' json. */
.val();
System.out.println(json);
And the given result is (of course, the results are different each time):
{
"name": "Cecila Starbird",
"userName": "moistben",
"email": "randiexyst@hotmail.co.uk",
"profiles": [
{
"profileId": 964,
"profileAdded": "Mar 19, 1973 12:00:00 AM"
},
{
"profileId": 854,
"profileAdded": "Jun 3, 1978 12:00:00 AM"
}
]
}
Later edit:
The new preferred way of generating json is the following: https://www.mockneat.com/tutorial/#json-and-xml
Disclaimer: I am the author of the library.