Recursive JSON merging with type overriding

PHP Hard json

Task «Recursive JSON merging with type overriding»

Write a PHP script that accepts two JSON objects (each on a separate line of stdin) and performs a recursive merge. If keys match and both values are objects (associative arrays), the merge should be recursive. If at least one value is not an object, then the resulting object should contain the value from the second JSON, but with type conversion: if the type of the value differs from the original, the value should be converted to a string with the prefix 'converted:'. If the value is already a string, it remains unchanged. Output the resulting JSON with indentation (pretty print).

Input Format

Two strings, each containing a valid JSON object (associative array).

Output Format

One line — the final JSON object with indentation (JSON_PRETTY_PRINT).

main.php