# Buggy code
def js_to_json(code):
    COMMENT_RE = r"/\*(?:(?!\*/).)*?\*/|//[^\n]*"
    SKIP_RE = r"\s*(?:{comment})?\s*".format(comment=COMMENT_RE)
    INTEGER_TABLE = (
        (r"(?s)^(0[xX][0-9a-fA-F]+){skip}:?$".format(skip=SKIP_RE), 16),
        (r"(?s)^(0+[0-7]+){skip}:?$".format(skip=SKIP_RE), 8),
    )

    def fix_kv(m):
        v = m.group(0)
        if v in ("true", "false", "null"):
            return v
        elif v.startswith("/*") or v.startswith("//") or v == ",":
            return ""

        if v[0] in ("'", '"'):
            v = re.sub(
                r'(?s)\\.|"',
                lambda m: {
                    '"': '\\"',
                    "\\'": "'",
                    "\\\n": "",
                    "\\x": "\\u00",
                }.get(m.group(0), m.group(0)),
                v[1:-1],
            )

        for regex, base in INTEGER_TABLE:
            im = re.match(regex, v)
            if im:
                i = int(im.group(1), base)
                return '"%d":' % i if v.endswith(":") else "%d" % i

        return '"%s"' % v

    return re.sub(
        r"""(?sx)
        "(?:[^"\\]*(?:\\\\|\\['"nurtbfx/\n]))*[^"\\]*"|
        '(?:[^'\\]*(?:\\\\|\\['"nurtbfx/\n]))*[^'\\]*'|
        {comment}|,(?={skip}[\]}}])|
        [a-zA-Z_][.a-zA-Z_0-9]*|
        \b(?:0[xX][0-9a-fA-F]+|0+[0-7]+)(?:{skip}:)?|
        [0-9]+(?={skip}:)
        """.format(comment=COMMENT_RE, skip=SKIP_RE),
        fix_kv,
        code,
    )


# Traceback (json.decoder.JSONDecodeError)
$ python -m youtube_dl --verbose https://clips.twitch.tv/CarelessZealousKangarooNerfBlueBlaster
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['--verbose', 'https://clips.twitch.tv/CarelessZealousKangarooNerfBlueBlaster']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2017.11.15
[debug] Git HEAD: f610dbb05
[debug] Python version 3.6.3 - Linux-4.12.13-1-ARCH-x86_64-with-arch
[debug] exe versions: ffmpeg 3.4, ffprobe 3.4, rtmpdump 2.4
[debug] Proxy map: {}
[twitch:clips] CarelessZealousKangarooNerfBlueBlaster: Downloading webpage
ERROR: CarelessZealousKangarooNerfBlueBlaster: Failed to parse JSON  (caused by JSONDecodeError("Expecting ',' delimiter: line 38 column 78 (char 2178)",)); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see  https://yt-dl.org/update  on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
Traceback (most recent call last):
File "/tmp/youtube-dl/youtube_dl/extractor/common.py", line 686, in _parse_json
return json.loads(json_string)
File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.6/json/decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 38 column 78 (char 2178)
Traceback (most recent call last):
File "/tmp/youtube-dl/youtube_dl/extractor/common.py", line 686, in _parse_json
return json.loads(json_string)
File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.6/json/decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 38 column 78 (char 2178)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/tmp/youtube-dl/youtube_dl/YoutubeDL.py", line 784, in extract_info
ie_result = ie.extract(url)
File "/tmp/youtube-dl/youtube_dl/extractor/common.py", line 437, in extract
ie_result = self._real_extract(url)
File "/tmp/youtube-dl/youtube_dl/extractor/twitch.py", line 610, in _real_extract
video_id, transform_source=js_to_json)
File "/tmp/youtube-dl/youtube_dl/extractor/common.py", line 690, in _parse_json
raise ExtractorError(errmsg, cause=ve)
youtube_dl.utils.ExtractorError: CarelessZealousKangarooNerfBlueBlaster: Failed to parse JSON  (caused by JSONDecodeError("Expecting ',' delimiter: line 38 column 78 (char 2178)",)); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see  https://yt-dl.org/update  on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

# Fixed code
def js_to_json(code):
    COMMENT_RE = r"/\*(?:(?!\*/).)*?\*/|//[^\n]*"
    SKIP_RE = r"\s*(?:{comment})?\s*".format(comment=COMMENT_RE)
    INTEGER_TABLE = (
        (r"(?s)^(0[xX][0-9a-fA-F]+){skip}:?$".format(skip=SKIP_RE), 16),
        (r"(?s)^(0+[0-7]+){skip}:?$".format(skip=SKIP_RE), 8),
    )

    def fix_kv(m):
        v = m.group(0)
        if v in ("true", "false", "null"):
            return v
        elif v.startswith("/*") or v.startswith("//") or v == ",":
            return ""

        if v[0] in ("'", '"'):
            v = re.sub(
                r'(?s)\\.|"',
                lambda m: {
                    '"': '\\"',
                    "\\'": "'",
                    "\\\n": "",
                    "\\x": "\\u00",
                }.get(m.group(0), m.group(0)),
                v[1:-1],
            )

        for regex, base in INTEGER_TABLE:
            im = re.match(regex, v)
            if im:
                i = int(im.group(1), base)
                return '"%d":' % i if v.endswith(":") else "%d" % i

        return '"%s"' % v

    return re.sub(
        r"""(?sx)
        "(?:[^"\\]*(?:\\\\|\\['"nurtbfx/\n]))*[^"\\]*"|
        '(?:[^'\\]*(?:\\\\|\\['"nurtbfx/\n]))*[^'\\]*'|
        {comment}|,(?={skip}[\]}}])|
        (?:(?<![0-9])[eE]|[a-df-zA-DF-Z_])[.a-zA-Z_0-9]*|
        \b(?:0[xX][0-9a-fA-F]+|0+[0-7]+)(?:{skip}:)?|
        [0-9]+(?={skip}:)
        """.format(comment=COMMENT_RE, skip=SKIP_RE),
        fix_kv,
        code,
    )