SmartQueryTools

Rank Rows in JSON Files Online

Add a rank column to JSON files based on any column's values. Choose RANK, DENSE RANK, or ROW NUMBER, with optional partitioning — runs entirely in your browser.

How to rank Rows in JSON files

  1. Drop your file onto the upload area. It is loaded into the in-browser engine and the first 200 rows are shown.
  2. Choose the Sort by column and a direction: Highest first (the default) or Lowest first.
  3. Optionally pick a Partition by column so ranking restarts at 1 in each group, and change the output column name from rank if you like.
  4. Pick a rank method: RANK (gaps after ties: 1, 1, 3), DENSE RANK (no gaps: 1, 1, 2) or ROW NUMBER (always unique: 1, 2, 3). Click Add Rank Column.
  5. The rank column is added as the first column. Check the preview, then download in the same format you uploaded.

Your file is processed locally in your browser and is never uploaded. The free limit is 50 MB per file; larger files work if your device has the memory for them.

Worked example

A warehouse tracks how many orders each picker completed on the early and late shifts. The supervisor wants a leaderboard for each shift, and two early-shift pickers finished level.

Input (JSON)

[
  {
    "picker": "Maya",
    "shift": "Early",
    "orders_picked": 14
  },
  {
    "picker": "Tom",
    "shift": "Early",
    "orders_picked": 9
  },
  {
    "picker": "Ines",
    "shift": "Early",
    "orders_picked": 14
  },
  {
    "picker": "Kofi",
    "shift": "Late",
    "orders_picked": 11
  },
  {
    "picker": "Lena",
    "shift": "Late",
    "orders_picked": 7
  },
  {
    "picker": "Raj",
    "shift": "Late",
    "orders_picked": 12
  }
]

Settings

  • Sort by column: orders_picked
  • Direction: Highest first
  • Partition by: shift
  • Rank method: RANK
  • Output column name: rank

Result

rankpickershiftorders_picked
1MayaEarly14
1InesEarly14
3TomEarly9
1RajLate12
2KofiLate11
3LenaLate7

Ranking restarts for each shift. Maya and Ines both picked 14, so both are ranked 1, and RANK skips 2, so Tom is 3. With DENSE RANK Tom would be 2. With ROW NUMBER one of the tied pair would get 2, and which one is not fixed. Here the rows came back grouped by shift, but output row order is not guaranteed. Sort afterwards if order matters.

Working with JSON files

Each top-level key is a column, and its JSON type decides how values compare. Numbers rank by value. Strings rank by character code. true ranks above false with Highest first. A key whose values mix numbers and quoted strings is loaded as a JSON-typed column and ranks as text. Objects that lack the sort key get null and rank last. Two objects with the same Sort by value tie under RANK and DENSE RANK, whatever their other keys hold.

In the output array, the rank key is the first key of every object, followed by the original keys in their original order. Ranks are written as JSON numbers. Nested objects are carried through as they are, but you cannot sort or partition by a nested field such as player.team. Flatten the file first to make that field a top-level key. The order of objects in the array may differ from the input.

Frequently Asked Questions

Can I rank JSON records by a nested field?

Not directly. The Sort by list only shows top-level keys. Flatten the JSON first so the nested field becomes its own key, then rank by it.

Where does the rank key appear in each JSON object?

It is the first key in each object. The original keys follow in their original order.

What is the difference between RANK, DENSE RANK and ROW NUMBER?

RANK gives ties the same number and skips the next ones (1, 1, 3). DENSE RANK gives ties the same number with no gap (1, 1, 2). ROW NUMBER gives every row a unique number (1, 2, 3), and the order between tied rows is not fixed.

Can I rank by more than one column, for example to break ties?

No. The tool ranks by one Sort by column, optionally within one Partition by column. For multi-column ordering, use the SQL Query tool with RANK() OVER (ORDER BY a DESC, b ASC).

How do I keep only the top 3 in each group?

Rank with a partition, then use Filter to keep rows where the rank is 3 or less. Top N per Group does both steps in one go.

Related Tools