SmartQueryTools

Add Percent of Total to JSON Files Online

Add a percentage-of-total column to JSON files directly in your browser. Show each row's share of the grand total, or the share within each group — no upload required.

How to add Percent of Total to JSON files

  1. Drop your file onto the upload area. The first numeric column is pre-selected as the Value column.
  2. Choose the Value column. Only numeric columns are listed.
  3. Optionally choose a Group by column. With (none) each row is a share of the grand total. With a group, each row is a share of its group total and the output name switches to pct_of_group.
  4. Set Decimal places (default 2, up to 10) and edit the Output column name if you want a different name.
  5. Click Add % Column, check the preview, then download the file with the new column appended.

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 council finance officer has budget lines for two departments and wants each line as a share of its own department's budget. One line has not been costed yet.

Input (JSON)

[
  {
    "department": "Parks",
    "line_item": "Mowing contracts",
    "amount": 48000
  },
  {
    "department": "Parks",
    "line_item": "Playground repairs",
    "amount": 12000
  },
  {
    "department": "Parks",
    "line_item": "Tree planting",
    "amount": 20000
  },
  {
    "department": "Libraries",
    "line_item": "E-book licences",
    "amount": 30000
  },
  {
    "department": "Libraries",
    "line_item": "Late-night opening",
    "amount": null
  },
  {
    "department": "Libraries",
    "line_item": "Children's programmes",
    "amount": 15000
  }
]

Settings

  • Value column: amount
  • Group by: department
  • Decimal places: 2
  • Output column name: pct_of_group

Result

departmentline_itemamountpct_of_group
ParksMowing contracts4800060
ParksPlayground repairs1200015
ParksTree planting2000025
LibrariesE-book licences3000066.67
LibrariesLate-night openingNULLNULL
LibrariesChildren's programmes1500033.33

Parks totals 80,000, so mowing is 48,000 / 80,000 = 60%. Libraries totals 45,000 because the empty amount is ignored in the sum. That line gets NULL rather than 0, and the other two Libraries lines still add up to 100. Without a Group by column, every line would be divided by the combined 125,000 instead, so mowing would be 38.4.

Working with JSON files

A key is offered as a Value column when its values are JSON numbers. If some objects store the amount as a string, like "amount": "48000", the key loads as text or with a mixed JSON type and cannot be used. Objects that do not have the key at all count as NULL. They get null in the new field and are left out of the total. Integers and decimals can be mixed freely in one key, such as 48000 and 12500.5, and still load as a single numeric column.

Grouping by a key that some objects lack puts those objects in a separate NULL group with its own total. The output is a JSON array where each object gains one new key, pct_of_total, pct_of_group or the name you typed, holding a number. A group whose values sum to zero produces null for every object in it rather than a division error. Nested objects are passed through unchanged.

Frequently Asked Questions

Why is my JSON amount field not listed?

At least some objects store it as a quoted string. Only keys that load as numbers are offered. Fix the source or cast the column first.

What is written for objects with no value?

The new key is written with null, and the object is not counted in its group total.

Do the percentages always add up to exactly 100?

Before rounding, the non-NULL rows in each group add up to 100. After rounding to your chosen decimal places, the total can be off by a small amount, such as 99.99 or 100.01. Increase Decimal places if that matters.

What happens with negative values or a zero total?

Negative values produce negative shares, and other rows can then go above 100. When a group totals exactly zero, every row in it gets NULL instead of an error.

Can I use a text column as the value?

No. Only numeric columns are listed. Convert the column with Cast Columns first if it holds numbers stored as text.

Related Tools