Sonnet

How to format or minify JSON on Android

APIs, exports and logs usually write JSON as one long line with no spaces. That’s efficient for machines and useless on a phone screen. Formatting (also called beautifying or pretty-printing) adds the line breaks and indentation back. Minifying does the opposite.

Short answer

Open the file in a JSON app that has a formatter. In Sonnet: open the file, tap Format or minify in the toolbar, then choose Format to indent it or Minify to put it on one line. Tap Save to write the result back to the file. It’s free and works offline. An online formatter works too, but only for data you don’t mind uploading.

Get Sonnet free No ads, no account, works offline.

What formatting actually changes

Only the whitespace between values. Here’s the same data both ways:

Minified
{"id":42,"name":"Ava","tags":["pro","beta"],"active":true}

Formatted
{
    "id": 42,
    "name": "Ava",
    "tags": [
        "pro",
        "beta"
    ],
    "active": true
}

The keys, the values and their order are the same in both. Any program that reads JSON treats the two versions identically, so you can switch between them as often as you like.

When to format, and when to minify

Step by step in Sonnet

  1. Open the file. Tap it in your file manager and choose Sonnet under Open with, or tap Open file inside the app. Pasted from somewhere? Save it as a file first. (Opening a JSON attachment covers chat and email.)
  2. Tap Format or minify in the docked toolbar.
  3. Choose Format or Minify. Format indents with four spaces per level.
  4. Save, copy or share. Save writes the new version to the file you opened. To keep the original untouched, use Share JSON instead: Copy JSON puts it on the clipboard, and Share with another app sends it as a .json file.

A small bonus: Sonnet reads almost-JSON with unquoted keys or 'single quotes'. When you format and save a file like that, it’s written back with proper double quotes, so the saved file is strict JSON.

Other ways to format JSON on a phone

Online formatters

Sites like JSONFormatter.org work in any mobile browser. Paste, tap format, copy. The catch is privacy: the JSON people format on their phones is often an API response with a token in it, or an export full of personal data. From the outside you can’t tell whether a site formats the data in your browser or sends it to its server. For anything sensitive, use an offline app.

Code editors

Some Android code editors can reformat a file, and they’re worth it if you already use one for other code. They show JSON as text rather than as a structure you can fold, which is fine for small files and tiring for big ones.

“It won’t format” — why that happens

A formatter has to parse the JSON before it can lay it out again. Sonnet repairs the most common syntax errors (missing or trailing commas, unclosed brackets) when the file opens, so those format normally. Anything else, like a comment or a stray quote inside a string, leaves nothing valid to format, and Sonnet will say the file isn’t valid JSON. Invalid JSON: what the error means and how to fix it goes through each cause.

The other common reason is size. Very large files take a lot of memory to parse on a phone. Sonnet opens files up to 20 MB for free, or 50 MB with the one-time Pro unlock. Beyond that, see how to open a large JSON file on Android.

Format JSON on your phone

Sonnet formats and minifies JSON offline, shows it as a collapsible tree, and lets you edit it with a tap. No ads, no account. Free on Google Play, with an optional one-time Pro unlock for bigger files and search.

Get it on Google Play