affaan-m/ECC · error · ValueError

application request must be a JSON object

Error message

application request must be a JSON object

What it means

load_application_request() reads a local JSON file and requires the top-level parsed value to be a JSON object (dict). The library throws this because the whole request model (baseline, source, candidates, inserts) is keyed-field based; an array, string, number or null at the top level cannot carry the required fields, so it fails fast instead of raising confusing downstream errors.

Solutions

  1. Wrap the file's top-level content in a JSON object with the required keys (baseline, source, audio, protected_intervals).
  2. Check the first non-whitespace character of the file: `[`, `"`, a digit, or `null`/`true`/`false` means it is not an object — fix the producer.
  3. Regenerate the request via whatever upstream tool compiles the full application config, not a partial export.
  4. If you only have the inner payload, embed it: {"baseline": ..., "source": ..., ...} before passing the path.

Example fix

// before (request.json)
[{"baseline": {...}}, ...]

// after
{"baseline": {...}, "source": {...}, "audio": [], "protected_intervals": [...]}
Defensive patterns

Strategy: validation

Validate before calling

import json
def ensure_json_object(path):
    with open(path, encoding="utf-8") as f:
        value = json.load(f)
    if not isinstance(value, dict):
        raise TypeError(f"{path}: top-level JSON must be an object, got {type(value).__name__}")
    return value

Type guard

def is_json_object(value) -> bool:
    return isinstance(value, dict)

Try / catch

try:
    request = load_application_request(path)
except ValueError as exc:
    if "must be a JSON object" in str(exc):
        print(f"{path}: top level must be {{...}} — fix the producer")
    raise

Prevention

When it happens

Trigger: Calling load_application_request(path) where the file contains valid JSON whose top-level value is not an object — e.g. a bare JSON array `[...]`, a quoted string, a number, `true`, or `null`.

Common situations: Hand-edited request files that start with a list of baselines; a script that dumps `json.dumps(items)` of a list instead of wrapping it in an object; exporting only the `candidates` array; a tool writing `null` on an empty export.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/0979f62710fd933b. Report an issue: GitHub.

Appendix: source

Thrown at skills/taste-application/scripts/tasteforge/integration.py:166

                or _identity(before) != _identity(after)):
            raise ValueError("artifact changed during reading")
        if expected_hash is not None and digest.hexdigest() != expected_hash:
            raise ValueError("artifact SHA-256 mismatch")
        return _load_json(b"".join(chunks)) if parse_json else None
    except (OSError, AttributeError) as exc:
        raise ValueError("local artifact unavailable or unsafe") from exc
    finally:
        if descriptor is not None:
            os.close(descriptor)
        if parent is not None:
            os.close(parent)


def load_application_request(path: str | Path) -> dict:
    """Load only a bounded resident request; never follow a config symlink."""
    value = _read_local(str(Path(path).absolute()), parse_json=True)
    if not isinstance(value, dict):
        raise ValueError("application request must be a JSON object")
    return value


def _load_json(data: bytes) -> Any:
    def unique(pairs):
        result = {}
        for key, value in pairs:
            if key in result:
                raise ValueError("duplicate JSON field")
            result[key] = value
        return result

    try:
        value = json.loads(data, object_pairs_hook=unique)
        _canonical(value)
        return value
    except (UnicodeError, RecursionError) as exc:
        raise ValueError("invalid JSON artifact") from exc

View on GitHub (pinned to 8321021c54)