MySQL JSON diff procedure
You are missing a second part of the diff.

I've added the missing part, renamed the variables a bit to make it easier to work with, and added some comments.

DELIMITER $$

DROP PROCEDURE IF EXISTS JSON_OBJECT_DIFF $$

CREATE PROCEDURE JSON_OBJECT_DIFF(IN a JSON, IN b JSON, INOUT aResult JSON, INOUT bResult JSON)
BEGIN
    DECLARE aKeys, bKeys JSON;
    DECLARE currentKey, currentKeyPath TEXT;
    DECLARE aVal, bVal JSON;
    DECLARE aKeysLength, bKeysLength, aHasKey, bHasKey INT;
    DECLARE i INT DEFAULT 0;

    SELECT JSON_KEYS(a) INTO aKeys;
    SELECT JSON_KEYS(b) INTO bKeys;
    SELECT JSON_LENGTH(aKeys) INTO aKeysLength;
    SELECT JSON_LENGTH(bKeys) INTO bKeysLength;

    # Iterate keys in `a` as `currentKey`:
    # * If exists in `b` and !=, insert `a(currentKey)` and `b(currentKey)` into `aResult` and `bResult`
    # * If does not exist in `b`, insert `a(currentKey)` into `aResult`

    WHILE i &lt; aKeysLength DO
        SELECT JSON_EXTRACT(aKeys, CONCAT('$[', i, ']')) INTO currentKey; /* Already quoted */
        SELECT CONCAT('$.', currentKey) INTO currentKeyPath;
        SELECT JSON_EXTRACT(a, currentKeyPath) INTO aVal;

        SELECT JSON_CONTAINS_PATH(b, 'one', currentKeyPath) INTO bHasKey;

        IF bHasKey = 1 THEN
            SELECT JSON_EXTRACT(b, currentKeyPath) INTO bVal;

            IF aVal != bVal THEN
                SELECT JSON_INSERT(aResult, currentKeyPath, aVal) INTO aResult;
                SELECT JSON_INSERT(bResult, currentKeyPath, bVal) INTO bResult;
            end if;
        ELSE
            SELECT JSON_INSERT(aResult, currentKeyPath, aVal) INTO aResult;
        END IF;

        SET i = i + 1;
    END WHILE;

    # Iterate keys in `b` as `currentKey`:
    # * If does not exist in `a`, insert `b(currentKey)` into `bResult`

    SET i = 0;
    WHILE i &lt; bKeysLength DO
        SELECT JSON_EXTRACT(bKeys, CONCAT('$[', i, ']')) INTO currentKey; /* Already quoted */
        SELECT CONCAT('$.', currentKey) INTO currentKeyPath;

        SELECT JSON_CONTAINS_PATH(a, 'one', currentKeyPath) INTO aHasKey;

        IF aHasKey = 0 THEN
            SELECT JSON_EXTRACT(b, currentKeyPath) INTO bVal;
            SELECT JSON_INSERT(bResult, currentKeyPath, bVal) INTO bResult;
        END IF;

        SET i = i + 1;
    END WHILE;
END $$