ytdl-org/youtube-dl · error · ValueError

Unknown value:

Error message

Unknown value: 

What it means

Raised by js_to_json() in youtube_dl.utils when parsing JavaScript (e.g. player configuration or JSON embedded in a webpage) with strict=True. A token in the JS object literal could not be converted to a valid JSON value: it is neither a quoted string, a number, true/false/null, nor a recognized identifier from the vars mapping. In strict mode the converter refuses to guess, so it raises ValueError('Unknown value: ' + v).

Source

Thrown at youtube_dl/utils.py:4627

                i = int(im.group(1), base)
                return ('"%s":' if v.endswith(':') else '%s') % inv(i)

        if v in vars:
            try:
                if not strict:
                    json.loads(vars[v])
            except JSONDecodeError:
                return inv(json.dumps(vars[v]))
            else:
                return inv(vars[v])

        if not strict:
            v = try_call(inv, args=(v,), default=v)
            if v in ('true', 'false'):
                return v
            return '"{0}"'.format(v)

        raise ValueError('Unknown value: ' + v)

    def create_map(mobj):
        return json.dumps(dict(json.loads(js_to_json(mobj.group(1) or '[]', vars=vars))))

    code = re.sub(r'new Map\((\[.*?\])?\)', create_map, code)
    if not strict:
        code = re.sub(r'new Date\((".+")\)', r'\g<1>', code)
        code = re.sub(r'new \w+\((.*?)\)', lambda m: json.dumps(m.group(0)), code)
        code = re.sub(r'parseInt\([^\d]+(\d+)[^\d]+\)', r'\1', code)
        code = re.sub(r'\(function\([^)]*\)\s*\{[^}]*\}\s*\)\s*\(\s*(["\'][^)]*["\'])\s*\)', r'\1', code)

    return re.sub(r'''(?sx)
        {str_}|
        {comment}|
        ,(?={skip}[\]}}])|
        void\s0|
        !*(?:(?<!\d)[eE]|[a-df-zA-DF-Z_$])[.a-zA-Z_$0-9]*|
        (?:\b|!+)0(?:[xX][\da-fA-F]+|[0-7]+)(?:{skip}:)?|

View on GitHub (pinned to 956b8c5855)

Solutions

  1. Call js_to_json with strict=False so unrecognized bare values are quoted as strings instead of raising.
  2. Pass a vars dict (js_to_json(code, vars={'foo': 'bar'})) mapping the bare identifiers to their JSON-serializable values.
  3. Pre-clean the JS: strip function wrappers, parseInt(...), new Date(...) etc. before conversion (the non-strict path does this with regexes).
  4. If you hit this inside an extractor for a specific site, report/update the extractor — the site's markup changed.

Example fix

// before
import json
from youtube_dl.utils import js_to_json
data = json.loads(js_to_json(js_text, strict=True))  # raises on bare identifiers

// after
import json
from youtube_dl.utils import js_to_json
data = json.loads(js_to_json(js_text, strict=False))  # unknown values become quoted strings
Defensive patterns

Strategy: fallback

Validate before calling

import json
from youtube_dl.utils import js_to_json

def parse_js_json(js_text, vars=None):
    try:
        return json.loads(js_to_json(js_text, vars=vars, strict=True))
    except ValueError:
        # retry non-strict: unknown bare values become quoted strings
        return json.loads(js_to_json(js_text, vars=vars, strict=False))

Try / catch

try:
    data = json.loads(js_to_json(code, strict=True))
except ValueError:
    data = json.loads(js_to_json(code, vars=known_vars, strict=False))

Prevention

When it happens

Trigger: Calling js_to_json(js_object_text, strict=True) (directly, or via a helper like json.loads(js_to_json(...)) in an extractor) where the JS source contains a bare unquoted value such as {v: foo}, a JS expression like new Something(...), an identifier not present in the vars dict, or a malformed literal. With strict=False the same input would be wrapped in quotes instead of raising.

Common situations: A website changes its player config and now embeds JS-only constructs (unquoted identifiers, function calls, Date objects) where JSON was expected; extractor regression after a site redesign; passing raw JS that was previously cleaned by non-strict preprocessing.

Related errors


AI-assisted analysis of ytdl-org/youtube-dl@956b8c5855 (2026-08-14). Data as JSON: /api/errors/88b528befd668fcc. Report an issue: GitHub.