Code formatting guide

How to Format JSON, XML and Code Online

JSON, XML and code snippets are often copied from APIs, logs, websites, database tools, browser consoles, spreadsheets, documentation pages or automation scripts. When the content is minified, compressed or badly indented, it becomes difficult to read and easy to break. A formatter turns messy text into structured, readable output so you can inspect it, debug it and share it more confidently.

This guide explains how to format JSON, XML and common code snippets online, what each formatting option means, how to identify common errors and how to use SHB ToolBox tools for cleaner development and data workflows.

Format your data or code now

Use dedicated tools for JSON, XML and general code formatting.

Why formatting matters

Formatting does not usually change the meaning of the data or code. It changes the visual structure. Indentation, line breaks and spacing help humans understand what belongs together. This is especially important for nested JSON objects, XML tags, SQL queries, HTML structures and long script snippets.

Good formatting helps you:

  • Find missing commas, brackets, quotes or closing tags.
  • Understand nested data structures more quickly.
  • Share code with another person in a readable way.
  • Review API responses and configuration files.
  • Compare before and after changes.
  • Prepare code snippets for documentation, support tickets or debugging.

JSON formatting explained

JSON is widely used in APIs, web apps, configuration files, browser storage, automation tools and JavaScript projects. JSON uses objects, arrays, strings, numbers, booleans and null values. A small mistake, such as a missing comma or an extra trailing comma, can make JSON invalid.

Minified JSON example

{"orderId":1001,"customer":{"name":"John","city":"Dubai"},"items":[{"sku":"A1","qty":2},{"sku":"B2","qty":1}]}

Formatted JSON example

{
  "orderId": 1001,
  "customer": {
    "name": "John",
    "city": "Dubai"
  },
  "items": [
    {
      "sku": "A1",
      "qty": 2
    },
    {
      "sku": "B2",
      "qty": 1
    }
  ]
}

The formatted version is easier to inspect because nested objects and arrays are clearly separated. You can see that customer is an object and items is an array of objects.

How to use the JSON Formatter

  1. Open the JSON Formatter.
  2. Paste your JSON data into the input box.
  3. Click format or use the available formatting option.
  4. Check for validation errors if the JSON is invalid.
  5. Copy or download the formatted output.
  6. Use minify if you need compact JSON for storage or transfer.

Common JSON errors

Missing comma

JSON values inside an object or array must be separated by commas.

Trailing comma

JSON does not allow a comma after the final item in an object or array.

Single quotes

JSON strings and keys must use double quotes, not single quotes.

Unquoted keys

Object keys must be quoted in valid JSON.

Broken brackets

Every opening bracket or brace must have a matching closing bracket or brace.

Invalid comments

Standard JSON does not support comments like // or /* */.

XML formatting explained

XML is used in feeds, documents, configuration files, integrations, invoices, legacy systems, sitemaps and many business data formats. XML uses tags, attributes and nested elements. Formatting XML makes it easier to see the parent-child structure.

Unformatted XML example

<order><id>1001</id><customer city="Dubai">John</customer><total>250</total></order>

Formatted XML example

<order>
  <id>1001</id>
  <customer city="Dubai">John</customer>
  <total>250</total>
</order>

The formatted XML clearly shows that id, customer and total belong inside order. This makes troubleshooting much easier when files contain many levels of nesting.

How to use the XML Formatter

  1. Open the XML Formatter.
  2. Paste XML data into the input area.
  3. Format it to add indentation and line breaks.
  4. Check for missing closing tags or incorrect nesting.
  5. Copy or download the cleaned XML output.

Common XML errors

Missing closing tag

Every opened tag should usually have a matching closing tag.

Incorrect nesting

Tags must close in the correct order. Inner tags should close before outer tags.

Invalid attribute quotes

Attribute values should be quoted properly, usually with double quotes.

Special characters

Characters like & may need escaping in XML content.

Code formatting explained

Code formatting is useful when you copy code from an email, documentation page, browser console, SQL editor, spreadsheet cell or AI response. A formatter can improve readability by adding indentation and line breaks. This helps with SQL, HTML, CSS, JavaScript, Apps Script, VBA and other scripts.

How to use the Code Formatter

  1. Open the Code Formatter.
  2. Choose the language or let the app detect the type where available.
  3. Paste your code snippet.
  4. Format the code to improve indentation and readability.
  5. Review the result carefully before using it in production.
  6. Copy or download the formatted code.

SQL formatting example

SQL queries often become difficult to read when SELECT fields, JOIN clauses and WHERE conditions are written on one line. Formatting separates each part of the query.

SELECT
  T0."DocNum",
  T0."DocDate",
  T1."ItemCode",
  T1."Quantity"
FROM
  OPDN T0
INNER JOIN
  PDN1 T1 ON T0."DocEntry" = T1."DocEntry"
WHERE
  T0."DocDate" BETWEEN [%0] AND [%1]
ORDER BY
  T0."DocDate";

This is easier to read because the selected columns, table joins, condition and ordering are clearly separated.

Formatting vs validating vs fixing

ActionWhat it doesWhat it does not do
FormattingImproves layout, indentation and readability.Does not guarantee the logic is correct.
ValidationChecks whether the structure is valid, such as JSON syntax.Does not confirm business meaning is correct.
FixingRequires understanding the actual error and intended result.Should not be fully automatic for important code.

Minify vs beautify

Beautifying makes content easier for humans to read. Minifying makes content smaller by removing unnecessary spaces and line breaks. Use beautify when debugging or reviewing. Use minify when you need compact output for a file, API or website.

Beautify

Adds line breaks and indentation. Best for reading, debugging and sharing.

Minify

Removes extra spaces and line breaks. Best for compact storage or transfer.

Privacy and safety tips

Before pasting code or data into any online tool, check whether it contains secrets. Avoid sharing passwords, private API keys, access tokens, customer records or confidential business data. For sensitive data, remove or mask private values before formatting.

  • Remove API keys before sharing code snippets.
  • Do not paste live passwords or private credentials.
  • Mask customer phone numbers and emails if not needed.
  • Keep backups of original code before editing.
  • Review formatted output before using it in production.

Common use cases

API response review

Format JSON returned by an API to inspect fields, arrays and nested objects.

Configuration cleanup

Format JSON or XML configuration files before editing.

SQL query sharing

Format SQL queries before sending them to a colleague or support team.

Apps Script or VBA review

Clean pasted script snippets before editing or saving them.

HTML and CSS snippets

Make copied website code easier to inspect and modify.

Error investigation

Use formatting to find missing brackets, broken tags or misplaced commas.

Best practices before using formatted output

  • Check that the formatter did not change string values.
  • Validate JSON before sending it to an API.
  • Test SQL queries in a safe environment before running on real data.
  • Use version control or backups for important code.
  • Do not assume formatted code is automatically correct.
  • Use a dedicated validator when strict compliance matters.

Final checklist

  • Choose the correct formatter: JSON, XML or code.
  • Paste only the content that needs formatting.
  • Remove sensitive values before using online tools.
  • Review validation errors carefully.
  • Copy or download the output only after checking it.
  • Test code before using it in production.

Frequently asked questions

Does formatting change my code?

Formatting should mainly change spacing and indentation, but always review output before using it.

Why is my JSON invalid?

Common reasons include missing commas, single quotes, trailing commas or unclosed brackets.

Can XML be formatted if tags are broken?

Badly broken XML may need fixing before it can be formatted correctly.

Should I paste API keys into a formatter?

No. Remove private keys, tokens and passwords before using any online formatting tool.