Browsers & softwarePractical guides

JSON formats successfully but loses a value? Check duplicate object keys

Successful formatting does not establish that JSON object names are unique. Keep the original text, inspect repeated names within each object and check the receiving program. Once text has become an object, an earlier value may no longer be recoverable from that result.

An angled close-up of syntax-highlighted code on a monitor
Illustrative photo: Patrick Martin · Unsplash License

Key Takeaways

Check decoded names in the original object before accepting a parsed result. KitNelo preserves both retries members in this example, while JavaScript JSON.parse leaves the later value, 3. Resolve the conflict from the intended field meaning rather than assuming the last value is correct.

In this article

Formatting and field completeness are separate checks

RFC 8259’s object guidance recommends unique names. With duplicate names, receivers can retain the last value, reject the object or behave differently. Acceptance by one parser therefore does not establish agreement across receiving systems.

Our JSON and SQL formatting review covers types and query meaning. This guide addresses an earlier failure: writing a name twice within one object can still produce a successfully formatted document.

Reproduce the difference with two retries members

This original teaching input contains no credentials. Paste it into the JSON formatter, choose Format and check that retries: 1 and retries: 3 remain. The current formatter arranges source tokens; it neither flags duplicate names nor chooses a value for you.

Passing the same original text to JavaScript JSON.parse produces a retries value of 3. That is evidence about this JavaScript operation, not every language. Download the formatted JSON and inspect both names again: a completed download does not resolve the conflict.

Retain this original JSON

{"job":"demo","retries":1,"retries":3}
Both repeated names belong to the same outer object.

Check the receiver separately

const raw = "{\"job\":\"demo\",\"retries\":1,\"retries\":3}";
console.log(JSON.parse(raw).retries); // 3 in JavaScript
Run in your own JavaScript test environment; the comment records the checked result for this input.

Different escape spellings can identify the same name

The names "qty" and "\u0071ty" decode to qty. I-JSON’s object constraint compares names after escape processing and prohibits these duplicates. I-JSON is a stricter interoperability profile; this does not mean every RFC 8259 parser rejects the text as a syntax error.

For the fixed sample {"qty":2,"\u0071ty":5}, formatting preserves both spellings and JavaScript parsing leaves qty equal to 5. Searching only for identical quoted strings misses this case. A programmatic check needs awareness of string escapes and object scope, rather than a regular expression counting words across the file.

Two separate objects in an array may each contain one qty without creating this kind of duplicate. Compare names within their containing object. For a separate explanation of character representation, see encoding and Unicode round-trip checks.

Confirm meaning before removing a member or changing structure

If the configuration owner confirms that the intended retry count is 3, a valid repair is {"job":"demo","retries":3}, retaining the original for comparison. If the values describe distinct records, use an array or different fields under the receiving contract. Do not invent a sum of 1 and 3.

Submit the unique-name version to the actual receiver’s test environment and inspect the field and configuration behavior. Record resolution only after source review, structural checks and receiving behavior agree. Without receiver access, leave that acceptance step unresolved.

Classify the structure before repairing it
Source structureFindingNext action
Two retries members in one objectConflicting field meaningConfirm one value or redesign the fields
qty and its escaped equivalentDuplicate decoded nameCompare semantic names
One qty in each of two array objectsNot a duplicate within one objectCheck each object and the receiver contract

Keep the original and the reason for the repair

Record the file version, containing object, conflicting values, chosen change and the field owner or contract supporting it. Reproduce sensitive configurations with a redacted small sample rather than a public ticket containing secrets. A formatter does not validate a schema, required fields, business rules or permission settings.

Further reading & sources

Put the guide into practice

Open the relevant tool, preview the result and check your exported file.