Skip to main content

Overview

MocklyAPI provides powerful query capabilities for JSON array responses. You can filter, sort, and limit your mock data using URL query parameters. Operations are applied in this order:
  1. Filtering - Narrow down results based on conditions
  2. Ordering - Sort the filtered results
  3. Limiting - Restrict the number of results returned
These operations only work when your mock data is a JSON array. Single objects or non-JSON responses will be returned as-is.

Query Parameters

URL Encoding

The filters parameter must be URL-encoded when it contains special characters like =, &, [, ].

Why URL Encoding is Required

When you include multiple filter conditions, the & character needs to be encoded as %26 to prevent it from being interpreted as a query parameter separator.

Encoding Examples

❌ Incorrect (will only apply first filter):
✅ Correct (URL-encoded):

Common Character Encodings

Filtering

Apply conditions to narrow down your results using the filters query parameter.

Supported Operators

Filter Syntax

Filters use query string format and support:
  • Simple equality: filters=status=active
  • Operators: filters=status[$eq]=active
  • Multiple conditions (AND logic): filters=status=active&role=admin
  • Nested fields: filters=user.name=John

Filter Examples

Simple equality:
Case-insensitive matching:
Multiple conditions (AND):
Not equals:
Nested field filtering:

Ordering

Sort your results by any field using order_by and order_direction parameters.

Syntax

Examples

Ascending order (default):
Descending order:
Sort nested fields:

Limiting

Restrict the number of results returned using the limit parameter.

Syntax

Examples

Get first 5 results:
No limit (return all):
The limit is applied after filtering and ordering. Set limit=0 to return an empty array.

Combining Operations

You can combine filtering, ordering, and limiting in a single request.

Example Request

This will:
  1. Filter for records where status is “active” AND role is “user”
  2. Sort by createdAt in descending order
  3. Return only the first 3 results

Example usage

Sample Dataset

This dataset demonstrates both simple fields and nested object structures:

Query Examples & Results

Example 1: Filter active users
Result:

Example 2: Order by age descending
Result:

Example 3: Active users, newest first, limit 2
Result:

Example 4: Case-insensitive email search
Result:

Example 5: Exclude admins, youngest first
Result:

Example 6: Filter by nested country (USA)
Result:

Example 7: Order by first name ascending (Nested path)
Result:
Nested Path Support:
  • Use dot notation to access nested properties at any depth (e.g., profile.address.city)
  • Ordering supports nested paths for both ascending and descending sorts

Limitations & Conditions

Important Constraints:
  • JSON Arrays Only: Operations only apply to JSON array responses. Single objects are returned unchanged.
  • AND Logic: Multiple filter conditions use AND logic (all must match). OR logic is not supported.
  • Supported Operators: Only $eq, $eqi, $ne, $nei are supported. Other operators will result an error.
  • Nested Path Support: Use dot notation for nested fields (e.g., user.profile.age)
  • URL Encoding Required: Always URL-encode the filters parameter to avoid parsing errors

Error Examples

Unsupported operator:
Invalid limit:
Missing URL encoding (common mistake):

Tips & Best Practices

  • Always URL Encode: Use your programming language’s URL encoding function to encode the filters parameter
  • Test Incrementally: Test filters, ordering, and limits separately before combining
  • Nested Fields: Take advantage of dot notation for complex data structures
  • Performance: Limiting results can improve response times for large datasets