Plist Integer and Real Number Types in JSON
Understand how Apple plist integer and real (floating-point) elements are converted to JSON numbers, and how the reverse inference works.
Detailed Explanation
Numeric Types in Plist
Apple plist distinguishes between two numeric types: <integer> for whole numbers and <real> for floating-point values. JSON has a single number type for both.
Plist Example
<dict>
<key>MaxRetries</key>
<integer>5</integer>
<key>Timeout</key>
<real>30.5</real>
<key>Version</key>
<integer>3</integer>
<key>ScaleFactor</key>
<real>2.0</real>
</dict>
JSON Output
{
"MaxRetries": 5,
"Timeout": 30.5,
"Version": 3,
"ScaleFactor": 2
}
Type Inference for Reverse Conversion
When converting JSON back to plist, the tool uses Number.isInteger() to decide between <integer> and <real>. A JSON value of 2.0 that JavaScript evaluates as 2 (integer) will become <integer>2</integer>. If you need <real>2.0</real>, you would need to manually adjust the output.
Large Numbers
Plist <integer> supports 64-bit signed integers (up to 9,223,372,036,854,775,807). JSON numbers are IEEE 754 double-precision floating-point, which safely represents integers up to 2^53. For very large integers, precision loss can occur during conversion.
Use Case
Essential when migrating macOS application settings that mix integer counts (retry limits, port numbers) with floating-point values (timeouts, scale factors) into JSON-based configuration systems.