[Python] How to compare two JSON objects with the same elements in a different order equal?

Discussão em 'Python' iniciado por Stack, Setembro 24, 2024.

  1. Stack

    Stack Membro Participativo

    How can I test whether two JSON objects are equal in python, disregarding the order of lists?

    For example ...

    JSON document a:

    {
    "errors": [
    {"error": "invalid", "field": "email"},
    {"error": "required", "field": "name"}
    ],
    "success": false
    }


    JSON document b:

    {
    "success": false,
    "errors": [
    {"error": "required", "field": "name"},
    {"error": "invalid", "field": "email"}
    ]
    }


    a and b should compare equal, even though the order of the "errors" lists are different.

    Continue reading...

Compartilhe esta Página