Getting started overview
This guide outlines the essential steps to begin using FakeJSON for generating synthetic data. The process involves creating an account, obtaining an API key, and making an initial API request to confirm functionality. FakeJSON is designed to streamline development and testing workflows by providing customizable JSON data without manual creation.
The service supports various data types and allows for the definition of complex JSON structures. Developers can define fields and their corresponding data types (e.g., names, emails, dates, numbers) within a JSON schema, and FakeJSON generates a response populated with randomized, type-appropriate data. For a comprehensive list of supported data types and options, refer to the FakeJSON data types documentation.
Below is a quick reference for the getting started process:
| Step | What to do | Where |
|---|---|---|
| 1. Account Creation | Sign up for a new FakeJSON account. | FakeJSON signup page |
| 2. API Key Retrieval | Locate and copy your unique API key from the dashboard. | FakeJSON dashboard |
| 3. First Request | Construct and execute a basic API call using cURL or a programming language. | Your terminal or development environment |
| 4. Verification | Confirm the API returns a valid JSON response with generated data. | API response output |
Create an account and get keys
To access the FakeJSON API, an account is required. FakeJSON offers a free tier that includes 500 requests per month, which is sufficient for initial testing and development. Paid plans are available for higher request volumes, starting at $19 per month for 10,000 requests.
Account creation
- Navigate to the FakeJSON signup page.
- Provide a valid email address and create a password.
- Complete any required CAPTCHA or email verification steps.
- Once registered, you will be redirected to your FakeJSON dashboard.
API key retrieval
Your API key is essential for authenticating requests to the FakeJSON API. It is a unique identifier tied to your account and must be kept secure. Do not expose your API key in client-side code or public repositories.
- Log in to your FakeJSON dashboard.
- Locate the section labeled 'API Key' or similar.
- Copy the displayed API key. This key will be included in your API requests, typically as a query parameter or an HTTP header.
Your first request
After obtaining your API key, you can make your first request to the FakeJSON API. This example demonstrates how to generate a simple JSON object containing a user's name and email address. The API allows for dynamic schema definition directly within the request URL or body.
Basic request structure
The FakeJSON API endpoint for generating data is https://api.fakejson.com/q. You will append your API key and the desired JSON schema to this URL.
Example schema for a single user:
{
"name": "{{name}}",
"email": "{{email}}"
}
In this schema, {{name}} and {{email}} are placeholders that FakeJSON interprets and replaces with generated data. For a complete list of available placeholders, consult the FakeJSON documentation on data types.
cURL example
Using cURL is a common way to test API endpoints from the command line. Replace YOUR_API_KEY with your actual API key.
curl -X GET "https://api.fakejson.com/q?token=YOUR_API_KEY&data={\"name\":\"{{name}}\",\"email\":\"{{email}}\"}"
Expected successful response (data will vary):
{
"name": "John Doe",
"email": "[email protected]"
}
JavaScript (Fetch API) example
For web applications or Node.js environments, the Fetch API provides a modern way to make HTTP requests. Replace YOUR_API_KEY with your actual API key.
const apiKey = 'YOUR_API_KEY';
const schema = {
name: '{{name}}',
email: '{{email}}',
};
fetch(`https://api.fakejson.com/q?token=${apiKey}&data=${encodeURIComponent(JSON.stringify(schema))}`)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
Expected successful response (data will vary):
{
"name": "Jane Smith",
"email": "[email protected]"
}
Common next steps
Once you have successfully made your first request, consider these common next steps to further integrate FakeJSON into your development workflow:
- Explore advanced data types: Review the FakeJSON documentation on data types to understand the full range of supported data generators, including addresses, dates, lorem ipsum text, and more.
- Generate arrays of objects: Learn how to request multiple instances of a defined schema to populate lists or tables. The FakeJSON API allows specifying a count parameter to generate an array of JSON objects. For example,
&count=5will return an array of 5 user objects. - Define custom schemas: Experiment with more complex JSON structures, including nested objects and arrays, to match your application's data models. This can involve creating templates with specific field names and types that directly correspond to your database or API requirements.
- Integrate into testing frameworks: Incorporate FakeJSON into your unit tests, integration tests, or end-to-end tests to provide consistent and varied test data. For example, when testing a form submission, FakeJSON can generate diverse user inputs. Many testing frameworks, such as Google's Web Fundamentals on Testing, emphasize the importance of realistic test data.
- Set up local development proxies: For local development, configure a proxy to redirect requests for mock data to FakeJSON, allowing your frontend to receive realistic data without a backend dependency.
- Monitor usage: Keep track of your API request volume through the FakeJSON dashboard to manage your free tier limits or monitor usage against your paid plan.
Troubleshooting the first call
Encountering issues during your first API call is common. Here are some troubleshooting steps:
- Invalid API Key: Double-check that you have copied your API key correctly from your FakeJSON dashboard and that it is present in your request. An invalid key will typically result in an authentication error (e.g., HTTP 401 Unauthorized).
- Incorrect URL Encoding: When passing the JSON schema in the URL, ensure that it is properly URL-encoded. Characters like
{,},", and spaces must be encoded to prevent parsing errors. The cURL example uses backslashes to escape double quotes (\"), while the JavaScript example usesencodeURIComponent(). - Malformed JSON Schema: Verify that your JSON schema is syntactically correct. Even minor errors, like a missing comma or an unclosed brace, can lead to API errors. Use a JSON linter or validator if unsure.
- Rate Limiting: If you are making many requests in a short period, especially on the free tier, you might hit rate limits. The FakeJSON API will typically return an HTTP 429 Too Many Requests status code. Consult the FakeJSON rate limits documentation for details on limits and how to handle them.
- Network Issues: Ensure your internet connection is stable and that no firewalls or proxies are blocking your outgoing API requests. You can test basic connectivity with a simple
ping api.fakejson.comcommand. - Refer to documentation: The FakeJSON API reference provides detailed information on all available parameters and expected responses. Reviewing the specific endpoint documentation can help identify common pitfalls.