Plist String Values and Special Characters in JSON

Learn how plist string values with special characters, XML entities, and multi-line content are converted to JSON strings.

Advanced

Detailed Explanation

String Handling Between Plist and JSON

Strings are the most common type in plist files, but they have different escaping rules in XML vs JSON. Understanding these differences is important for correct conversion.

XML Entities in Plist

<dict>
  <key>CompanyName</key>
  <string>Smith &amp; Jones</string>
  <key>TagLine</key>
  <string>We say &quot;hello&quot; &amp; &lt;wave&gt;</string>
  <key>Description</key>
  <string>Line one
Line two
Line three</string>
  <key>EmptyValue</key>
  <string></string>
  <key>Path</key>
  <string>/Users/dev/My Files/project</string>
</dict>

JSON Output

{
  "CompanyName": "Smith & Jones",
  "TagLine": "We say \"hello\" & <wave>",
  "Description": "Line one\nLine two\nLine three",
  "EmptyValue": "",
  "Path": "/Users/dev/My Files/project"
}

XML Entity Decoding

When parsing plist XML, the browser's DOMParser automatically decodes XML entities: &amp; becomes &, &lt; becomes <, &quot; becomes ", and so on. The JSON output contains the decoded characters with JSON-appropriate escaping (double quotes become \", etc.).

Multi-line Strings

Plist XML preserves newlines within <string> elements. In JSON, these become \n escape sequences within the string value. The converter handles this automatically via JSON.stringify().

Reverse Conversion: JSON to Plist

When converting JSON strings to plist, special XML characters are escaped: & becomes &amp;, < becomes &lt;, > becomes &gt;, and " becomes &quot;. This ensures the generated plist XML is always valid.

Empty Strings

Empty <string></string> elements become empty JSON strings "". These are distinct from null values (which don't exist in plist).

Use Case

Important for developers dealing with plist files that contain user-facing text with special characters, file paths with spaces, or multi-line description fields.

Try It — Plist ↔ JSON Converter

Open full tool