-4

I am looking at any library (in java) that can help me generate a dummy JSON file to test my code for e.g The JSON file can contain random user profile data-name, address, zipcode

I searched StackOverflow and found this link, found the following link : How to generate JSON string in Java?

I think the suggested library https://github.com/DiUS/java-faker, seems to be useful, however because of security constraints I cannot use this particular library. Are there any more recommendations?

Anand
  • 191
  • 15

1 Answers1

1

Use for instance Faker, like that:

#!/usr/bin/env python3
from json import dumps
from faker import Faker


fake = Faker()

def user():
    return dict(
        name=fake.name(),
        address=fake.address(),
        bio=fake.text()
    )

print('[')
try:
    while True:
        print(dumps(user()))
        print(',')
except KeyboardInterrupt:
    # XXX: json array can not end with a comma
    print(dumps(user()))
    print(']')

You can use it like that:

python3 fake_user.py > users.json

Use Ctrl+C to stop it when the file is big enough

amirouche
  • 7,682
  • 6
  • 40
  • 94
  • Thank you. I have rephrased my question to state that I need java library. Apologies for not being clear in the original post. – Anand Feb 12 '18 at 08:39