Blog

Format JSON and copy a value’s JSON Pointer

Format a one-line API response in your browser, find a value in the tree, and copy its JSON Pointer. The examples also cover minification and syntax checks.

The English interface shows one-line JSON beside the indented output.

When an API returns a single line of JSON, adding line breaks makes the values easier to read. If you need to report that the second item is out of stock, include the path so someone else can locate the same value. Try both operations with a fictional product list in the JSON formatter, minifier, and validator. The browser processes the pasted data locally.

Make a one-line response easier to read

Paste this sample into “Input JSON”.

{"items":[{"sku":"A-001","stock":12},{"sku":"B-002","stock":0}]}
  1. Set “Indent” to 2 and click “Pretty →”.
  2. In “Output”, find the second entry in items. Its sku is B-002 and its stock is 0.
  3. To save the formatted result, click “Copy”, then paste it into an editor and save. For a compact single line, click “Minify →” before copying.
The English interface shows the product list in the input and JSON formatted with two-space indentation in the output.
The separate input and output fields let you compare the original line with the formatted hierarchy.

Find the second stock value’s path in the tree

  1. With the same input, click “Tree view”.
  2. Expand items, open [1], and select "stock": 0. Array indexes start at zero, so [1] is the second entry.
  3. Check that the selected JSON Pointer is /items/1/stock and click “Copy path”. Record the path along with the response you inspected.
The English tree shows the second entry under items, with /items/1/stock displayed for the selected stock value.
The path field shows where the selected value is located. The value itself is 0.

In a JSON Pointer, a slash in a key is written as ~1 and a tilde as ~0. For example, the single key stock/on-hand becomes stock~1on-hand. See RFC 6901 syntax.

Check the syntax when formatting fails

If you write the second entry as {"sku":"B-002","stock":0,}, the trailing comma before the closing brace causes a syntax error. Click “Validate” to check. If the browser supplies the error position, the tool shows the line and column. Remove the comma and run “Validate” again before formatting.

“Validate” checks JSON syntax. Consult the API documentation or schema for rules such as whether stock is required or can be negative.