Compare two json values for equality

Viewed 183

(Note that this is using the Preview JSON feature in BigQuery.)

Is there a simple way to compare two json values to see if they're equal, ignoring key-ordering, recursively, for example:

{a: 1, b:2}    ===      {b:2, a:1}

As an example:

WITH tbl AS (
    SELECT JSON '{"a": 1, "b": 2}' as a, JSON '{"b": 2, "a": 1}' as b
) SELECT a,b, a=b?? FROM tbl
1 Answers

Try below

SELECT a,b, TO_JSON_STRING(a) = TO_JSON_STRING(b) 
FROM tbl     

with result

enter image description here

Related