YAML Comparison Rules
Understand mappings, sequences, scalar types, comments, presentation, case options, numeric strings, and duplicate counts.
YAML comparison starts with the values produced by the parser, then applies the selected sequence and scalar-matching rules. Choose options from the meaning of your configuration, not from which settings produce the fewest differences.
What Data Compare examines
Data Compare compares three familiar YAML value shapes:
- Mappings become keyed objects. A missing or added key is structural, and changing the value associated with a key is a value change. Mapping key order is not significant.
- Sequences become ordered arrays. The selected sequence method determines how items are aligned.
- Scalars retain their parsed types, including strings, numbers, booleans, and null values. Quoting can change a scalar’s type.
For example, these mappings produce the same values even though their key order and layout differ:
service: billing
enabled: true
{
enabled: true,
service: billing
}
A renamed key, changed scalar, missing mapping entry, or added sequence item is still a semantic difference unless a selected option explicitly makes the values equivalent.
Scalar types and numeric strings
Unquoted YAML scalars can parse as non-string types. In this fragment, enabled is a boolean, port is a number, and description is a string:
enabled: true
port: 8080
description: "8080"
By default, the number 8080 and the string "8080" are different values. Enable Numeric String Equals Number when a configuration treats them as interchangeable. The option is opt-in; it does not turn every string into a number or make unrelated textual values equivalent.
The same distinction applies to other types: quoting true produces a string rather than the boolean true. There is no general option to ignore scalar types. Review the parsed type when an apparently identical value is reported as changed.
Match sequences
Consider this Base sequence:
regions:
- us-east
- eu-west
- ap-south
And this Contrast sequence:
regions:
- us-east
- ap-south
- eu-west
By Index
By Index is the default. It compares each item with the item at the same position. In the example, positions 1 and 2 both change because eu-west and ap-south exchange places.
Use By Index when positions have stable meaning, such as fixed configuration slots or ordered snapshots. An insertion near the beginning can make many later items appear changed because their positions shift.
LCS
LCS uses the Longest Common Subsequence to align equal items while preserving order. It is useful when a mostly ordered sequence gains or loses entries and you want those insertions and deletions aligned to unchanged items.
LCS remains order-sensitive. A move is represented through deletion and insertion rather than as a special move operation, and an insertion can have more than one valid alignment when values repeat.
Unordered
Unordered ignores item order and matches values as a multiset. In the example, all three regions have the same values and occurrence counts, so Unordered reports them as equal.
Duplicate counts still matter. These sequences are not equal under Unordered because Base contains two admin entries and Contrast contains one:
# Base
roles: [admin, admin, editor]
# Contrast
roles: [editor, admin]
Use Unordered for collections such as tags or permissions only when order is irrelevant. It is not a set comparison and does not discard duplicates.
Key and value case options
Ignore Key Case
This option applies to mapping keys. With it enabled, these keys can match:
Service:
Status: ACTIVE
service:
status: ACTIVE
Leave it off when differently cased keys are distinct in your configuration. Enabling it can intentionally suppress key-name differences throughout nested mappings.
Ignore Value Case
This option applies to string values. With it enabled, ACTIVE and active compare as equal:
status: ACTIVE
status: active
Do not enable it for case-sensitive identifiers, tokens, paths, or user content. It changes value comparison, not mapping-key matching.
The case options and numeric-string option solve different problems. For example, Ignore Value Case does not make the number 8080 equal to the string "8080"; that requires Numeric String Equals Number.
Comments and presentation
Comments do not become values in Data Compare. Changing or removing a comment therefore does not create a semantic difference:
# Deployed setting
retries: 3
# Proposed setting
retries: 3
Presentation is likewise separate from the parsed data. When two inputs produce the same values, these changes do not independently create Data Compare differences:
- reordering mapping keys;
- changing indentation or line layout without changing structure;
- changing quote style without changing the scalar value or type;
- using flow or block notation for the same mapping or sequence.
A presentation edit can still change data. For example, indentation that moves a key into a different mapping changes structure, and adding quotes around true changes a boolean to a string. Data Compare follows the resulting value, not the visual appearance alone.
Original-source results and Git Diff
Data Compare uses parsed values and the selected rules to calculate differences. It then maps result paths to the original YAML source lines, so its aligned editors can show your comments, quoting, key order, and layout alongside semantic highlights.
Git Diff instead compares the original Base and Contrast text line by line. It can show comment, formatting, quoting, or mapping-order edits even when Data Compare reports Same. Conversely, semantic options can suppress a value difference without changing the original-text diff.
The result page exposes semantic Settings in Data Compare. Changing a rule recalculates Data Compare; Git Diff remains a read-only view of the original input text.
Troubleshooting
Reordered sequence items produce differences. By Index and LCS preserve order. Select Unordered only if order has no meaning, and check duplicate occurrence counts.
One insertion shifts many values. By Index aligns positions. Try LCS for an ordered sequence with insertions or deletions.
A comment or formatting edit appears only in Git Diff. This is expected when the parsed values are unchanged: Data Compare compares values, while Git Diff compares original text.
A number and quoted numeric string differ. Check their parsed types and enable Numeric String Equals Number only when that equivalence is valid for the field.
A case difference disappears. Check whether key-case or value-case ignoring is enabled. Return to Data Compare to review the active settings.
Start with the YAML Getting Started guide for a complete Base-to-Contrast example, result navigation, URL loading, sharing, and privacy guidance.