Calculator

What the String to JSON Converter does

String to JSON Converter: converts Status, JSON and Top-level type from String, Indent and Sort keys. Example: indent 2 spaces and sort keys Keep order gives status Converted: 1 string layer removed.

Give the String to JSON Converter your String, Indent and Sort keys and it works out Status, JSON and Top-level type. Change any input and the output follows immediately.

Pasting a production payload into an unknown web tool is a real risk, which is why this one stays local. That is usually what brings engineers checking an encoding here.

The work is done by JavaScript already loaded in your browser, so your input never crosses the network.

The field table, the method and a worked example are documented after the tool for anyone who wants to check the working.

What do the String to JSON Converter fields mean?

The String to JSON Converter uses 3 inputs. None of the boxes start empty. The page loads with a worked set of values you can edit or replace.

FieldWhat to enterDefault
String paste or type any amount of text "{\"event\":\"order.paid\",\"orderId\":48213,\"amount\":1499.5,\"currency\":\"INR\",\"items\":[{\"sku\":\"TS-204\",\"qty\":2},{\"sku\":\"MG-118\",\"qty\":1}],\"customer\":{\"id\":\"c_9f31\",\"newsletter\":false},\"note\":\"Deliver after 6 pm\\nRing twice\"}"
Indent choose from 2 spaces, 4 spaces, 1 tab or Minified (no indent) 2 spaces
Sort keys choose from Keep order or A to Z Keep order

How does the String to JSON Converter work?

Status, JSON, Top-level type, String layers removed, Keys and Levels deep ← f(String, Indent, Sort keys)

Each output is derived from the inputs above in a single pass; there is no hidden state carried between runs, so the same inputs always give the same conversion.

Bad input produces a message, not a silently incorrect figure.

Worked example

These are the values the String to JSON Converter loads by default, and the result it produces from them. Open the tool above and you will find precisely these figures already in place.

Inputs
String"{\"event\":\"order.paid\",\"orderId\":48213,\"amount\":1…
Indent2 spaces
Sort keysKeep order
Result
StatusConverted: 1 string layer removed
JSON{ "event": "order.paid", "orderId": 48213, "amount": 1499.5, "currency": "INR", "items": [ {…
Top-level typeObject
String layers removed1
Keys13
Levels deep4

A string that holds JSON is not JSON yet

JSON.stringify applied to a document gives JSON text. Applied to that text a second time, it gives a JSON string: the whole document on one line inside double quotes, with every inner quote written as \" and every line break as \n. That second form is what turns up in log fields, queue messages, database text columns and webhook envelopes, and it has to be parsed once per layer before any key in it can be read.

Already JSON{"id":7}Formatted only. No layer to remove
Encoded once"{\"id\":7}"One layer removed. This is what JSON.stringify makes of a JSON text
Encoded twice"\"{\\\"id\\\":7}\""Two layers removed in one pass
Escaped, outer quotes lost{\"id\":7}Read as one layer. Common when a value is copied out of a log viewer
A plain string"hello"Stays a string, because there is no document inside it

Worth knowing

  • The rules are strict JSON as defined by RFC 8259: keys and text in double quotes, no trailing comma, no comments, and no NaN, Infinity or undefined. Text that breaks one of them is a JavaScript object literal, JSON5 or JSONC, which are useful formats but different ones.
  • Inside a JSON string, a line break, a tab or any other control character has to be written as an escape. A raw one is the usual reason a hand-edited payload stops parsing.
  • Each layer of encoding roughly doubles the backslashes in front of an inner quote: one, then three, then seven. Counting them tells you how many times a payload was stringified before it reached you.
  • When the mistake sits inside an encoded layer, the line and column still refer to the text you pasted, not to the unescaped text, so "Go to error" lands on the character to fix.
  • A string value is never guessed into another type. "42", "true" and "null" stay strings, because an order number or a postcode that happens to be all digits must not turn into a number.
  • In code the same job is one parse per layer: JSON.parse(JSON.parse(s)) in JavaScript, json.loads(json.loads(s)) in Python. If you control the system that produces the payload, the better fix is to stop it encoding twice.
  • Numbers pass through the browser's JSON parser, so an integer above 9,007,199,254,740,991 (2 to the power 53, minus 1) loses precision, as it would in any JavaScript program. Identifiers that large belong in strings.

Sources: RFC 8259: The JSON Data Interchange Format · MDN: JSON.parse()

How to use it

  1. Paste your content into String.
  2. Pick a value for Indent: the options are 2 spaces, 4 spaces, 1 tab or Minified (no indent).
  3. Pick a value for Sort keys: the options are Keep order or A to Z.
  4. Results update continuously rather than on submit.
  5. Check Status, JSON, Top-level type, String layers removed, Keys and Levels deep on the right.
  6. Use Copy Link if you want the same setup again later, or Print for a paper copy.

What this tool does not do

  • Processing happens in your browser, so extremely large inputs are bounded by available memory.
  • Output follows the common convention for this format; a specific toolchain may have its own house style.
  • It handles the common case well and the unusual case literally.

Frequently asked questions

The form asks for String, Indent and Sort keys. Each field is pre-filled with a sensible default, so the form is usable immediately, without filling anything in first.

With the values loaded when the page opens, status comes out as Converted: 1 string layer removed. Nudge one field at a time to see which one the answer is most sensitive to.

No. Your browser is doing the computing, so we could not see the values even if we wanted to.

Free for any use, personal or commercial.

As accurate as the inputs allow. The arithmetic itself introduces no error beyond display rounding.

YoursTools Team
Product & Engineering

Builds and maintains every calculator on YoursTools.