Add Lag / Lead Column to JSON Files Online
Add a LAG or LEAD column to JSON files to shift any column forward or backward by N rows. See previous day's sales, next value in a sequence, or any time-shifted comparison — runs entirely in your browser.
How to add Lag / Lead Column to JSON files
- Drop your file onto the upload area. The first 200 rows are shown.
- Choose a Direction. LAG takes the value from an earlier row and names the new column prev_value. LEAD takes it from a later row and names it next_value.
- Pick the Value column and the Offset (rows), which defaults to 1. Set Order by to your date or sequence column so "previous" means what you expect.
- Optionally set Partition by so the shift restarts for each group, and a Default value for rows that have no earlier or later row. Rename the output column if you like.
- Click Add LAG Column (or Add LEAD Column), check the preview, then download the file.
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 hydrologist has daily temperature readings from two weather stations in one file and wants the previous day's reading next to each day, without mixing the stations.
Input (JSON)
[
{
"station": "WLG-01",
"reading_date": "2026-07-01",
"temp_c": 9.4
},
{
"station": "AKL-02",
"reading_date": "2026-07-01",
"temp_c": 14.1
},
{
"station": "WLG-01",
"reading_date": "2026-07-02",
"temp_c": 8.1
},
{
"station": "AKL-02",
"reading_date": "2026-07-02",
"temp_c": 15.3
},
{
"station": "WLG-01",
"reading_date": "2026-07-03",
"temp_c": 10.2
}
]Settings
- Direction: LAG
- Value column: temp_c
- Offset: 1
- Order by: reading_date
- Partition by: station
- Default: (blank, NULL)
- Output column name: prev_value
Result
| station | reading_date | temp_c | prev_value |
|---|---|---|---|
| WLG-01 | 2026-07-01 | 9.4 | NULL |
| WLG-01 | 2026-07-02 | 8.1 | 9.4 |
| WLG-01 | 2026-07-03 | 10.2 | 8.1 |
| AKL-02 | 2026-07-01 | 14.1 | NULL |
| AKL-02 | 2026-07-02 | 15.3 | 14.1 |
Each station's first day has no earlier reading, so prev_value is NULL. The shift never crosses from one station to the other because of Partition by. The rows come back grouped by station, because that is how the window is computed. Sort by reading_date afterwards if you need the original interleaved order. A day-on-day change is then temp_c minus prev_value.
Working with JSON files
JSON arrays have a natural order, and without Order by the shift follows it as loaded. That is fine for a log that is already sorted, but set Order by anyway to make the result repeatable. Keys with ISO date strings like "2026-07-02" are usually detected as dates. Timestamps with a T separator may stay as text. ISO text still sorts correctly because the format runs from year down to second.
Objects missing the value key are treated as NULL and pass NULL to the next object's prev_value. The shifted value keeps its JSON type. Numbers stay numbers, strings stay strings, and nested objects can be shifted too, which gives each object a copy of the previous object's nested value. The download is a JSON array where each object has the new key added last. Boundary objects get null. With Partition by set, objects come back grouped by that key, so the array order can differ from the input.
Frequently Asked Questions
Can I LAG a nested object in a JSON file?
Yes. Pick the key that holds the nested object as the Value column. The previous object's nested value is copied whole into the new key.
What do boundary objects get in the JSON output?
null, unless you set a Default value. The default is converted to the value column's type.
What is the difference between LAG and LEAD?
LAG reads from N rows earlier, for example yesterday's value. LEAD reads from N rows later, for example the next appointment date. Both add one new column and leave the original rows in place.
What does the Default value do?
It fills rows that have no row N positions away, such as the first row of each partition for LAG. The value you type is converted to the value column's type. A number works for a numeric column, but text that is not a number causes a conversion error.
Why is Order by optional?
Without it the shift follows the order rows were loaded, which is often file order but is not guaranteed. Set Order by whenever row order matters, which is almost always.
Related Tools
Add Calculated Column to JSON Files Online
Add a new column to JSON files computed from an arithmetic expression over existing columns. No formulas, no code — just point and click.
Calculate Date Difference in JSON Files Online
Calculate the difference between two date or timestamp columns in JSON files directly in your browser. Output in days, months, years, hours, minutes, or seconds — no upload required.
Filter JSON Files Online
Filter rows in JSON files by column value, directly in your browser. Your data stays on your device.
Add Lag / Lead Column to CSV Files Online
Add a LAG or LEAD column to CSV files to shift any column forward or backward by N rows. See previous day's sales, next value in a sequence, or any time-shifted comparison — runs entirely in your browser.
Add Lag / Lead Column to Excel Files Online
Add a LAG or LEAD column to Excel files to shift any column forward or backward by N rows. See previous day's sales, next value in a sequence, or any time-shifted comparison — runs entirely in your browser.
Add Lag / Lead Column to Parquet Files Online
Add a LAG or LEAD column to Parquet files to shift any column forward or backward by N rows. See previous day's sales, next value in a sequence, or any time-shifted comparison — runs entirely in your browser.
JSON Viewer Online
View and inspect JSON files directly in your browser. Browse rows, check column names and data types — no upload required, your data stays on your device.
Convert JSON to Parquet Online
Convert JSON files to Parquet format directly in your browser. No upload required — your data never leaves your device.