JSONX isn't a single, universally standardized language, so “writing brackets” with it depends on which tool you mean. In the common JavaScript/JSX-style JSONX extensions, square brackets mark arrays and braces mark objects, while literal bracket characters inside strings need no special encoding beyond normal JSON string rules. If your tool instead refers to IBM's XML-to-JSON convention (also called JSONx), brackets appear only as characters inside JSON string values. The key condition: confirm your JSONX tool's spec first, then follow the rules below rather than guessing.
First, pin down what "JSONX" means in your toolchain
The name gets applied to at least three different things, and bracket behavior differs across them. Knowing which one you're holding prevents most errors before you type a single character.
The first is a JSON-with-JSX flavor used in some front-end configurations and parsers, where JSON-like data can carry JSX expressions. Here brackets behave like ordinary JSON plus whatever the surrounding framework allows.
The second is IBM's JSONx, an XML representation of JSON used in some DataPower and related integration contexts. In that format every JSON value becomes an XML element, and any bracket you see is inside text content, encoded per XML rules (for example, < for < if you ever nest markup).
The third is a family of small libraries and config dialects that adopt "JSONX" as a brand name for extended JSON (comments, trailing commas, typed values, or template expressions). Their bracket rules usually mirror JSON, but some allow single quotes or unquoted keys.
So the practical first action is a spec check, not syntax. Open your tool's documentation or its parser source and answer three questions: Does it accept strict JSON only, or extensions? Are arrays and objects still [] and {}? How are literal bracket characters represented inside strings?
If you can't find a spec, run a two-minute probe: feed the parser a tiny document containing an array, an object, and a string with [ and { inside quotes. Note which constructs parse and which throw. That result is your ground truth, and it beats any assumption.
The core bracket rules that hold across nearly all JSONX variants
Once you've confirmed the dialect, the baseline is straightforward. Arrays are ordered lists written with square brackets, and objects are key-value maps written with curly braces. Commas separate elements; a trailing comma is invalid in strict JSON but accepted in many extended dialects.
A minimal array looks like this:
{"tags": ["alpha", "beta", "gamma"]}
A nested object with an array inside:
{"user": {"roles": ["admin", "editor"], "active": true}}
Square brackets always denote position-indexed sequences, and curly braces always denote named fields in strict JSON. Mixing them ([{"id": 1}]) is both legal and common: an array of objects. The bracket you "write" is really a decision about whether the data is a list or a map, and the delimiters follow from that decision.
Empty containers are written [] and {}. Deep nesting should be indented so each bracket pair is visually traceable; unbalanced brackets are the single most common syntax failure, and indentation exposes them fastest.
Two rules trip people up repeatedly. First, keys in strict JSON must be double-quoted strings, so {name: "x"} is invalid while {"name": "x"} is valid. Second, brackets inside string values are just characters—"note": "use [brackets] here" needs no escaping at all in JSON. People over-escape them anyway, producing "[", which strict JSON rejects as an invalid escape.
Writing brackets inside strings without breaking the document
Literal square or curly brackets inside a string value need no escaping in JSON or in most JSONX dialects. What you do need to escape is the double quote (") and the backslash (\), because those conflict with string delimiters. So a value like {"path": "array"} is perfectly valid JSON, and so is {"template": "{user.id}"}.
Trouble starts when your JSONX string contains something that looks like a template expression. In JSX-flavored JSONX, a value such as "label": "{count} items" may be interpreted as an expression by the outer framework even though the JSON parser itself is fine. The fix is dialect-specific: either escape the braces per that framework's rules ({}), wrap the value so it's treated as a plain string, or move template logic out of the JSON entirely and interpolate after parsing.
You should also decide how to handle brackets that appear in data you don't control. If you're embedding user-supplied text, quotes and backslashes are the real hazard, not brackets. Run such values through a serializer rather than hand-editing strings.
XML-based JSONx complicates this further. Because the document is XML, <, >, and & must be entity-encoded in text content, but [ and { are generally safe as literal characters. Bracket content that includes these special characters must be encoded, so "a < b" becomes "a < b" inside the JSONx string. If you ever see a bracket sequence that includes <, treat it as XML text, not raw JSON.
A reliable step-by-step procedure for generating bracket-bearing JSONX
Prerequisites: your dialect confirmed, a validator available (most JSON parsers print line and column on failure), and your source data separated from its presentation. Follow these in order.
1: Decide structure first. For each field, ask "list or map?" Lists get square brackets, maps get curly braces. Write a skeleton with empty containers and no values yet.
2: Fill values inside the containers, keeping keys double-quoted, and use null for unknown values rather than guessing.
3: Add nesting level by level, validating after each level rather than at the end. This isolates the offending bracket pair.
4: Handle string values containing quotes, backslashes, or framework-sensitive braces. Escape " as ", \ as \, and apply dialect-specific brace escaping only if the framework requires it.
5: Serialize from real data when possible. Most languages' standard JSON serializers will always produce balanced brackets and correct escaping; hand-writing is where errors creep in.
6: Validate the final document with your tool's own parser, not just a generic JSON parser, because extensions differ.
7: Check the round trip: parse the document, re-serialize it, and compare. Any structural surprise means a misread dialect.
Success check: the parser accepts the document, round-tripping preserves structure and values, and bracket pairs are balanced. If the parser reports an error at a bracket, the cause is almost always a missing comma, an unquoted key, a trailing comma in a strict parser, or a string break that swallowed the brace.
Stop condition: if the validator and your read of the spec disagree about fundamental syntax, don't keep patching—get the versioned spec or a tool owner involved, because further edits will compound the mismatch.
Worked examples so you can pattern-match
Start with a nested list of objects. Suppose you need a shopping cart. The outer structure is an object ({}), the items field is an array ([]), and each item is an object ({}), so the shape is {"items": [{...}, {...}]}. Filled in, that reads as an object holding an array whose elements are objects—three bracket decisions stacked cleanly.
Next, a value that contains brackets. If a field holds a string like "regex": "[a-z]+", that's valid JSON with no escaping; the square brackets inside the quotes are simply characters. But if the field holds a string ending in a backslash, like "path": "C:\temp\[x]", you must double each backslash (\) so the parser doesn't treat the following character as an escape. This is where hand-editing usually fails.
A third example demonstrates a common design choice. Two documents can represent the same information. One uses an array of pairs: {"headers": [["Accept", "text/html"], ["X-Id", "7"]]}. The other uses an object: {"headers": {"Accept": "text/html", "X-Id": "7"}}. The array form preserves order and allows duplicate keys; the object form is easier to look up. Writing brackets correctly here means choosing the container that matches your access pattern, not just typing a delimiter.
Troubleshooting the bracket errors you'll actually hit
The symptoms below map to a small set of causes, and each fix is reversible, so start with the cheapest checks.
Unbalanced brackets: the parser complains at end-of-file or at a deep nesting point. Reindent the whole document; a missing ] or } almost always becomes visible within seconds.
Unexpected token comma or bracket: usually a trailing comma where the dialect is strict, or a missing comma between two elements. Remember strict JSON forbids a comma before ] or }.
Unquoted key errors: a curly-brace map contains something like {key: 1}. Add double quotes around every key.
A string that "eats" a bracket: a value contains an unescaped quote, so the parser reads past the intended closing quote and treats the next bracket as string content. Escape the interior quotes as ".
Framework template conflict: in JSX-flavored JSONX, a string like "{x}" may be evaluated rather than kept literal. Escape per the framework or move interpolation outside the JSON.
If you've checked all five and your error persists, the likely problem is a dialect mismatch rather than a typo. At that point, testing one small construct at a time against the real parser is the correct move; guessing at syntax wastes more time than a five-line probe.
Limits, trade-offs, and when not to hand-write brackets
Hand-writing bracketed JSONX is fine for small payloads and fixtures. It degrades quickly as nesting and string content grow, because every quote and brace is a chance to break the document. The trade-off is control versus correctness: manual editing gives you formatting and comments in extended dialects, while serializers give you guaranteed balance and escaping. For anything generated repeatedly or containing user data, favor the serializer and reserve hand-editing for one-off tweaks.
There's also a compatibility cost to extensions. A document that relies on a trailing comma, an unquoted key, or JSX template braces may parse in your tool and fail in a downstream strict JSON consumer. If the data crosses a boundary—an API, a database, another team's parser—test against the strictest consumer in the chain, not the most permissive.
Finally, brackets represent meaning, not decoration. The most expensive mistake isn't a syntax error, which a validator catches; it's choosing the wrong container, so a list of one header becomes a map or two duplicate keys silently collapse. Validate structure against the reader's expectations, not just the parser's approval.
FAQ
Do I need to escape square brackets in JSON string values? No. In standard JSON they're ordinary characters. Only double quotes, backslashes, and control characters require escaping.
Why does my JSX-flavored JSONX treat {name} as code? Because the outer framework interprets brace expressions in some contexts. Check that tool's rules—either escape the braces or move interpolation out of the JSON.
Can I use single quotes instead of double quotes for JSONX? Only if your specific extended dialect allows it. Strict JSON requires double quotes, and downstream consumers may reject single quotes.
Does IBM-style JSONx change how I write brackets? It keeps JSON structure inside an XML document, so brackets remain characters in string values, but XML special characters like < and & must be entity-encoded because the document is XML.