Get started with json-schema-faker CDN

MIT licensed

JSON Schema Faker generates fake data based on provided JSON schemas.

Tags:
  • json
  • jsonschema
  • fake
  • mocks

Stable version

Copied!

How to start using json-schema-faker CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with json-schema-faker CDN - cdnhub.io</title>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/json-schema-faker.min.js"></script>
</head>
<body>
  <button id="generate">Generate Fake Data</button>
  <script>
    const JsonschemaFaker = require('json-schema-faker');

    document.getElementById('generate').addEventListener('click', () => {
      const schema = {
        title: 'Person',
        type: 'object',
        properties: {
          firstName: { type: 'string' },
          lastName: { type: 'string' },
          email: { type: 'string', format: 'email' },
          phoneNumber: { type: 'string', pattern: '^[0-9]{10}$' },
          address: {
            type: 'object',
            properties: {
              street: { type: 'string' },
              city: { type: 'string' },
              state: { type: 'string' },
              postcode: { type: 'string', pattern: '^[0-9]{5}([-0-9]{4})?$' },
              country: { type: 'string' },
            },
          },
        },
      };

      const generatedData = JsonschemaFaker.create(schema);
      console.log(generatedData);
    });
  </script>
</body>
</html>

All versions