'invalid_json']); } // backup backup_file($target); // atomic write $tmp = $target . '.tmp'; file_put_contents($tmp, json_encode($decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); rename($tmp, $target); json_response(['ok' => true]); } http_response_code(405); json_response(['error' => 'method_not_allowed']);