Using the Faker JS library in Fake Data

Fake Data extension comes bundled with Faker libraryopen in new window (formerly known as faker-js) and is used to generate all the values from the Default Generators. The library is open source and is used to generate random values in javascript.

In the next examples, we will see how to take advantage of this library in your custom generators.

Faker library is registered in the global variable faker. So you can use that in order to access its APIs. This will also make it easier while reading their documentation, since it uses the same global keyword.

Let's see how to generate random names with Fake Data and Faker:

return faker.person.fullName();

The above example will generate values like this:

Noah Bauch

We can of course combine the previous Hello world example with this one:
let name = faker.person.firstName();
return 'Hello, ' + name + '!';

And the result would be:

Hello, Otto!


Feel free to explore Faker's documentation in order to see all the generators that they offer: https://fakerjs.dev/guide/open in new window

INFO

Fake Data might not always include the very latest version of Faker library. In case there is a generator newly added in the library and is not available in Fake Data, feel free to reach out by email and request an update of the library and it will happen.