Function Repository Resource:

AssociationSameQ

Source Notebook

Check if associations are the same, irrespective of key-value pair order

Contributed by: Maximilien Tirard

ResourceFunction["AssociationSameQ"][assoc1,assoc2, ]

yields True if the associations are the same, up to reordering of key-value pairs.

Details

The order is also ignored for nested associations.
ResourceFunction["AssociationSameQ"] also works with more than two associations, giving True if all the associations are the same
AssociationSameQ[] and AssociationSameQ[expr] always yields True.

Examples

Basic Examples (2) 

AssociationSameQ ignores the key-value orders and looks at the keys and values themselves:

In[1]:=
ResourceFunction[
 "AssociationSameQ"][<|"a" -> 1, "b" -> 2|>, <|"b" -> 2, "a" -> 1|>]
Out[1]=

Normal usage of SameQ yields False if the associations are not in the same order:

In[2]:=
<|"a" -> 1, "b" -> 2|> === <|"b" -> 2, "a" -> 1|>
Out[2]=

Scope (2) 

The order is also ignored for nested associations:

In[3]:=
ResourceFunction[
 "AssociationSameQ"][<|"a" -> 1, "b" -> <|"b.x" -> 21, "b.y" -> 22|>|>, <|
  "b" -> <|"b.y" -> 22, "b.x" -> 21|>, "a" -> 1|>]
Out[3]=

AssociationSameQ can take more than two associations:

In[4]:=
ResourceFunction[
 "AssociationSameQ"][<|"a" -> 1, "b" -> 2, "c" -> 3|>, <|"b" -> 2, "c" -> 3, "a" -> 1|>, <|"c" -> 3, "a" -> 1, "b" -> 2|>]
Out[4]=

Publisher

Maximilien Tirard

Version History

  • 1.0.0 – 17 September 2025

Related Resources

License Information