Object to String Representation Converter
Convert objects to string representations and back. Supports JSON, JS literals, Python dicts, URL params, YAML, XML, and TypeScript interfaces.
About
Data interchange between systems fails when format assumptions are wrong. A Python dict uses True and single quotes. A JavaScript literal allows unquoted keys and trailing commas. A JSON payload requires double quotes and rejects undefined. Passing the wrong format to JSON.parse throws a SyntaxError and your pipeline halts. This tool performs real bidirectional conversion between 7 common object string representations: JSON, JS object literals, Python dicts, URL query strings, flat YAML, CSV key-value pairs, and XML. It normalizes quotes, replaces language-specific constants (None → null, True → true), strips trailing commas, and handles nested structures where the format supports them.
This tool does not use eval. All parsing is done through deterministic regex transformations and the native JSON.parse function. This means untrusted input will not execute arbitrary code. Limitation: the JS literal and Python dict parsers handle common patterns but cannot replicate a full language parser. Computed keys, template literals, and Python f-strings are not supported. For flat YAML, only single-level key: value pairs are parsed. Deeply nested YAML requires a dedicated parser.
Formulas
The conversion pipeline applies a chain of deterministic text transformations before invoking JSON.parse. No runtime code evaluation is used at any stage.
JS Literal → JSON normalization:
1. Replace single quotes ' with double quotes " (context-aware, skipping escaped sequences).
2. Quote unquoted keys: match pattern regex ([{,]\s*)(\w+)(\s*:) → $1"$2"$3.
3. Remove trailing commas: match ,\s*([}\]]) → $1.
4. Pass result to JSON.parse.
Python Dict → JSON normalization:
1. Replace True → true, False → false, None → null (word-boundary aware).
2. Apply same quote and comma normalization as JS literal path.
3. Pass result to JSON.parse.
URL Query String → Object:
Split on &, then each pair on first =. Apply decodeURIComponent to both key and value. Bracket notation a[b][c] is recursively resolved into nested objects.
Object → TypeScript Interface:
For each key k with value v, emit k: typeof(v). Arrays infer element type from first element. Nested objects generate nested interface blocks.
Where v = input value, k = object key, typeof = JavaScript type inference function, and regex = regular expression pattern matcher.
Reference Data
| Format | Key Quoting | String Quoting | Boolean Literals | Null Literal | Trailing Comma | Nesting Support | Example |
|---|---|---|---|---|---|---|---|
| JSON | Double quotes required | Double quotes only | true / false | null | Forbidden | Full | {"a": 1} |
| JS Object Literal | Optional (valid identifiers) | Single or double | true / false | null | Allowed | Full | {a: 1} |
| Python Dict | Single or double quotes | Single or double | True / False | None | Allowed | Full | {'a': 1} |
| URL Query String | No quoting | URL-encoded | String only | Empty string | N/A | Bracket notation | a=1&b=2 |
| Flat YAML | No quoting | Optional quotes | true / false | null or ~ | N/A | Single level only | a: 1 |
| CSV Key-Value | No quoting | No quoting | String only | Empty string | N/A | None | a=1,b=2 |
| XML | Tag names | Text nodes | String only | Empty tag or xsi:nil | N/A | Full | <a>1</a> |
| TypeScript Interface | Unquoted identifiers | Type annotations | boolean | null | Allowed | Nested interfaces | a: number; |
| JSON (Minified) | Double quotes required | Double quotes only | true / false | null | Forbidden | Full | {"a":1} |
| Properties File | No quoting | No quoting | String only | Empty string | N/A | Dot notation | a=1 |
| TOML (flat) | Bare or quoted | Double or single | true / false | Not supported | Allowed in arrays | Tables | a = 1 |
| INI File | No quoting | No quoting | String only | Empty string | N/A | Sections | [section]\na=1 |
Frequently Asked Questions
{[myVar]: 1} require runtime evaluation of the variable myVar. This converter uses static regex transformations and JSON.parse - it never executes code. Only literal identifier keys (e.g., {name: 'Alice'}) and quoted keys are supported. Wrap computed keys in quotes manually before converting.user[name]=Alice&user[age]=30 produces {"user": {"name": "Alice", "age": "30"}}. Note that all URL parameter values are strings. The converter does not infer numeric types from query strings because the URL specification treats all values as text. If you need typed values, convert to JSON first, then manually adjust types.(1, 2, 3) and sets {1, 2, 3} have no direct JSON equivalent. Tuples are syntactically ambiguous with parenthesized expressions, and sets collide with object notation. The converter handles dict literals only. Convert tuples to lists [1, 2, 3] in your Python source before pasting.|, >), anchors (&), aliases (*), and nested indentation require a full YAML parser (e.g., js-yaml). This tool covers the most common use case: simple configuration key-value pairs.[1, "hello", true] would be typed as number[] based on the first element. For truly mixed arrays, manually adjust the output to (number | string | boolean)[]. Empty arrays are typed as any[].jq. The 500KB limit comfortably handles objects with several thousand keys.