What happens to empty XML elements in JSON?
Answer for ParseBloom: An empty element becomes an empty string, while an element that was never present has no JSON property. Whitespace-only text also becomes an empty string. Repeated empty siblings form an array of empty strings. Check for property presence before treating an empty value as missing.
The distinction at a glance
In the middle row, r itself exists and is empty. There is no child e. The illustration uses short names; the full copyable fixtures below use empty.
Six copyable cases
Paste each XML snippet into the converter and click Convert to JSON. The JSON below is compacted for comparison; the tool displays indented JSON. These are synthetic inputs, so no private data is involved.
<r><empty/></r>{"r":{"empty":""}}The child is present. Its value is a string of length zero.
<r><empty></empty></r>{"r":{"empty":""}}The two XML spellings produce the same JSON. This output cannot tell which spelling was used.
<r><empty> </empty></r>{"r":{"empty":""}}This mapper trims text. Spaces that were meaningful to the producer disappear.
<r><present>A</present></r>{"r":{"present":"A"}}There is no empty property. An absent child is different from a present child with an empty value.
<r><empty/><empty/></r>{"r":{"empty":["",""]}}The repeated name triggers an array, even though both values are empty strings.
<r><empty id=""/></r>{"r":{"empty":{"_attributes":{"id":""}}}}An attribute changes the child's shape to an object. Its own empty value still survives.
Test presence before testing content
A common shortcut, if (!row.empty), treats an absent key, an empty string, and other falsy values alike. Use an own-property check when your application needs to distinguish “the XML supplier sent an empty field” from “the supplier did not send this field.” Then inspect the value's type, because repeated elements and attributed elements do not have the single-string shape.
const row = converted.r;
const sent = Object.hasOwn(row, 'empty');
if (!sent) {
// No <empty> child was present.
} else if (row.empty === '') {
// A single empty or whitespace-only child was present.
} else if (Array.isArray(row.empty)) {
// Repeated children: inspect each array entry.
} else if (typeof row.empty === 'object' && row.empty !== null) {
// Check _attributes and any child values.
}This code checks the JSON output of this particular mapper. It does not infer whether the XML used <empty/> or a separate closing tag, and it cannot recover whitespace removed by trimming.
Do not assume every converter uses an empty string
The JSON Checker XML-to-JSON page documents a different choice: empty elements become null. The CodeShack converter exposes mapping options such as attribute handling and type parsing. The JSON Formatter converter page provides another interface. Compare actual output before wiring a consumer to any converter's JSON shape.
A public Json.NET question about an empty XML element illustrates why this choice matters. The examples here answer it only for ParseBloom's mapping; they are not a claim about Json.NET.
For the related one-versus-many shape, see the repeated-elements guide. For attr-only objects and text-like IDs, see the attributes guide.