Skip to content

Instantly share code, notes, and snippets.

@milhomem
Created May 2, 2015 06:32
Show Gist options
  • Save milhomem/957b81e9f7f33ea15516 to your computer and use it in GitHub Desktop.
Save milhomem/957b81e9f7f33ea15516 to your computer and use it in GitHub Desktop.
Diff two Json files
cat /tmp/json_a | php -r '$f=file("php://stdin"); $a = json_decode(join($f), true); function ksortRecursive(&$array, $sort_flags = SORT_REGULAR) { if (!is_array($array)) return false; ksort($array, $sort_flags); foreach ($array as &$arr) { ksortRecursive($arr, $sort_flags); } return true; }; ksortRecursive($a); echo var_export($a,true);' > /tmp/json_a_sorted
cat /tmp/json_b | php -r '$f=file("php://stdin"); $a = json_decode(join($f), true); function ksortRecursive(&$array, $sort_flags = SORT_REGULAR) { if (!is_array($array)) return false; ksort($array, $sort_flags); foreach ($array as &$arr) { ksortRecursive($arr, $sort_flags); } return true; }; ksortRecursive($a); echo var_export($a,true);' > /tmp/json_b_sorted
diff /tmp/json_a_sorted /tmp/json_b_sorted -u --ignore-all-space
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment