jsonsql.dev 100% client-side
{ }

Query JSON with MongoDB Syntax

Filter, sort & project JSON data using MongoDB-style operators — no database needed

Data Map
Templates:
Run a query to see results
MongoDB mode

How to query JSON with MongoDB syntax online

jsonsql.dev lets you query JSON data using MongoDB-style syntax directly in your browser. No database needed, no data sent to any server — your JSON stays on your machine.

Paste your JSON — copy a JSON array from your API response, database export, or config file and paste it into the input editor.

Write a MongoDB query — use $eq, $gt, $in, $or, and other operators to filter your data. Add $sort, $limit, and $project to shape results.

View results — matching documents appear instantly as a formatted table or syntax-highlighted JSON. Click Copy to grab the results.

MongoDB query operators reference

MongoDB query syntax uses JSON objects with $ operators to express conditions — making it natural for developers already working with JSON data.

Category Operator Description Example
Comparison $eq Equal to { "status": { "$eq": "active" } }
$ne Not equal to { "status": { "$ne": "inactive" } }
$gt Greater than { "age": { "$gt": 30 } }
$gte Greater than or equal { "salary": { "$gte": 100000 } }
$lt Less than { "age": { "$lt": 25 } }
$lte Less than or equal { "price": { "$lte": 50 } }
Array $in Matches any value in array { "dept": { "$in": ["Eng", "Design"] } }
$nin Does not match any value { "status": { "$nin": ["deleted"] } }
Logical $and All conditions must match { "$and": [{ "a": 1 }, { "b": 2 }] }
$or At least one condition matches { "$or": [{ "a": 1 }, { "b": 2 }] }
$not Negates a condition { "age": { "$not": { "$lt": 18 } } }
Element $exists Field exists or not { "email": { "$exists": true } }
String $regex Matches regular expression { "name": { "$regex": "^A" } }
Control $sort Sort results (1=asc, -1=desc) { "$sort": { "salary": -1 } }
$limit Limit number of results { "$limit": 5 }
$skip Skip first N results { "$skip": 10 }
$project Select fields (1=include, 0=exclude) { "$project": { "name": 1 } }

MongoDB query examples

Practical examples using a realistic employee dataset. Paste the sample data (click "Sample Data" above) and try each query.

Exact match

{ "department": "Engineering" }
// Returns all employees in the Engineering department

Range query

{ "salary": { "$gte": 100000, "$lte": 150000 } }
// Returns employees with salary between $100K and $150K

Logical OR

{ "$or": [{ "department": "Engineering" }, { "department": "Sales" }] }
// Returns employees in Engineering OR Sales

IN operator

{ "department": { "$in": ["Engineering", "Design"] } }
// Returns employees in Engineering or Design (shorthand for $or)

Field exists

{ "email": { "$exists": true } }
// Returns documents that have an email field

Regex pattern

{ "name": { "$regex": "^A" } }
// Returns employees whose name starts with "A"

Sort and limit

{ "$sort": { "salary": -1 }, "$limit": 3 }
// Returns top 3 highest-paid employees

Project specific fields

{ "$project": { "name": 1, "salary": 1 } }
// Returns only name and salary for all employees

$sort, $limit, $skip, and $project

Control operators shape the output of your query without changing the filter conditions. They can be used at the top level alongside filter conditions, or nested under a $query key for explicit separation.

Sorting

Use $sort with 1 for ascending and -1 for descending. You can sort by multiple fields:

{ "$sort": { "department": 1, "salary": -1 } }
// Sort by department A-Z, then by salary highest first within each department

Pagination with $skip and $limit

Combine $skip and $limit to paginate through results:

// Page 1: first 5 results
{ "$sort": { "name": 1 }, "$limit": 5 }

// Page 2: skip first 5, take next 5
{ "$sort": { "name": 1 }, "$skip": 5, "$limit": 5 }

// Page 3: skip first 10, take next 5
{ "$sort": { "name": 1 }, "$skip": 10, "$limit": 5 }

Field selection with $project

Use $project to include only specific fields in the output. Set a field to 1 to include it, or 0 to exclude it:

// Include only name and department
{ "$project": { "name": 1, "department": 1 } }

// Combine with filter and sort
{
  "department": "Engineering",
  "$sort": { "salary": -1 },
  "$project": { "name": 1, "salary": 1 }
}

MongoDB syntax vs SQL vs JSONPath

Each query syntax has strengths. Choose the one that matches your data and familiarity:

Capability MongoDB SQL JSONPath
Filter by condition Full ($gt, $in, $regex) Full (WHERE) Basic ([age > 30])
Logical AND / OR Yes ($and, $or) Yes (AND, OR) No
Sorting Yes ($sort) Yes (ORDER BY) No
Pagination Yes ($skip + $limit) Yes (LIMIT) No
Field selection Yes ($project) Yes (SELECT cols) Yes ([*].field)
Aggregation No Yes (GROUP BY + COUNT, SUM) No
Regex matching Yes ($regex) Yes (LIKE) No
Nested navigation Dot notation in field names Limited Best
Query format JSON objects SQL strings Dot notation
Learning curve Medium (JSON + operators) Low (familiar SQL) Low

Try all three syntaxes on the same data: JSONPath query | SQL query | All query modes

When to use MongoDB query syntax

MongoDB query syntax is the best choice in these scenarios:

  • You already know MongoDB — if you work with MongoDB in your day job, the query syntax feels like home. No need to learn a different language.
  • Complex nested conditions$and and $or let you build arbitrarily complex filter trees using standard JSON nesting. This is more readable than long SQL WHERE clauses with parentheses.
  • When SQL feels like overkill — for simple "find documents matching X" queries, { "status": "active" } is shorter and more intuitive than SELECT * FROM data WHERE status = 'active'.
  • API testing and mocking — when testing MongoDB-backed APIs, you can paste your actual query objects and verify them against sample data without connecting to a database.
  • Prototyping queries — test MongoDB queries against sample JSON before running them on a real database. Iterate faster without risking production data.

Related tools

Frequently asked questions

How do I filter JSON with $gt and $lt?

Use comparison operators inside a field object. For example, { "age": { "$gt": 25, "$lt": 40 } } matches documents where age is between 25 and 40 (exclusive). You can also use $gte and $lte for inclusive bounds.

How do I use $or to match multiple conditions?

Wrap conditions in a $or array: { "$or": [{ "department": "Engineering" }, { "department": "Sales" }] }. A document matches if ANY condition in the array is true. You can nest $or inside $and and vice versa for complex logic.

What does $in do in MongoDB queries?

$in matches a field against an array of possible values. For example, { "status": { "$in": ["active", "pending"] } } matches documents where status is either "active" or "pending". It is a shorthand for multiple $or conditions on the same field.

How do I select specific fields with $project?

Add $project to your query and set fields to 1 (include) or 0 (exclude). For example: { "$project": { "name": 1, "salary": 1 } } returns only the name and salary fields for each matching document.

What is implicit $and in MongoDB queries?

When you put multiple conditions in the same query object, they are combined with AND automatically. For example, { "department": "Engineering", "salary": { "$gte": 100000 } } matches documents where BOTH conditions are true. This is equivalent to { "$and": [{ "department": "Engineering" }, { "salary": { "$gte": 100000 } }] }.

How does $exists work?

$exists checks whether a field is present in a document. { "email": { "$exists": true } } matches documents that have an email field (even if the value is null). { "email": { "$exists": false } } matches documents that do NOT have an email field.

Do I need a MongoDB database to use this tool?

No. This tool runs MongoDB-style queries entirely in your browser against any JSON array — no database, no server, no installation required. It is ideal for testing query syntax before deploying to a real MongoDB instance, or for ad-hoc filtering of API responses and JSON exports.

How do I use $regex to search text in JSON fields?

Use $regex inside a field filter: { "name": { "$regex": "^Al" } } matches documents where the name starts with "Al". The value is a standard JavaScript regular expression pattern. This is useful for partial matches, prefix searches, and pattern-based filtering.

How do I query nested fields with dot notation in MongoDB syntax?

Use quoted dot-notation keys: { "address.city": "Seattle" } matches documents where the nested city field inside address equals "Seattle". Dot notation works with all operators — for example { "config.retries": { "$gte": 3 } } filters on nested numeric fields.

What is the difference between $and and implicit AND in MongoDB queries?

Implicit AND is when you put multiple fields in one object: { "age": { "$gt": 25 }, "status": "active" }. Explicit $and is required when you need multiple conditions on the SAME field: { "$and": [{ "score": { "$gt": 50 } }, { "score": { "$lt": 90 } }] }. Both return documents matching all conditions.