private function formatJson($json)
    {
        $tab = '  ';
        $newJson = '';
        $indentLevel = 0;
        $inString = false;
        $len = strlen($json);
        for ($c = 0; $c < $len; $c++) {
            $char = $json [$c];
            switch ($char) {
                case '{':
                case '[':
                    if (!$inString) {
                        $newJson .= $char . "\n" .
                            str_repeat($tab, $indentLevel + 1);
                        $indentLevel++;
                    } else {
                        $newJson .= $char;
                    }
                    break;
                case '}':
                case ']':
                    if (!$inString) {
                        $indentLevel--;
                        $newJson .= "\n" .
                            str_repeat($tab, $indentLevel) . $char;
                    } else {
                        $newJson .= $char;
                    }
                    break;
                case ',':
                    if (!$inString) {
                        $newJson .= ",\n" .
                            str_repeat($tab, $indentLevel);
                    } else {
                        $newJson .= $char;
                    }
                    break;
                case ':':
                    if (!$inString) {
                        $newJson .= ': ';
                    } else {
                        $newJson .= $char;
                    }
                    break;
                case '"':
                    if ($c == 0) {
                        $inString = true;
                    } elseif ($c > 0 && $json [$c - 1] != '\\') {
                        $inString = !$inString;
                    }
                    // fall-through
                default:
                    $newJson .= $char;
                    break;
            }
        }

        return $newJson;
    }