phacility/phabricator · error · Exception

This document does not encode a valid JSON object and can no

Error message

This document does not encode a valid JSON object and can not be rendered as a Jupyter notebook.

What it means

The file parsed as valid JSON, but phutil_json_decode() returned a non-array (a scalar such as a number, string, or boolean). A notebook must be a JSON object at its root, so the engine refuses to render it. This is a type check one step beyond syntax: valid JSON, wrong shape.

Source

Thrown at src/applications/files/document/PhabricatorJupyterDocumentEngine.php:319

      ),
      $notebook_table);

    return $container;
  }

  private function newCells($content, $for_diff) {
    try {
      $data = phutil_json_decode($content);
    } catch (PhutilJSONParserException $ex) {
      throw new Exception(
        pht(
          'This is not a valid JSON document and can not be rendered as '.
          'a Jupyter notebook: %s.',
          $ex->getMessage()));
    }

    if (!is_array($data)) {
      throw new Exception(
        pht(
          'This document does not encode a valid JSON object and can not '.
          'be rendered as a Jupyter notebook.'));
    }

    $nbformat = idx($data, 'nbformat');
    if ($nbformat == null || !strlen($nbformat)) {
      throw new Exception(
        pht(
          'This document is missing an "nbformat" field. Jupyter notebooks '.
          'must have this field.'));
    }

    if ($nbformat !== 4) {
      throw new Exception(
        pht(
          'This Jupyter notebook uses an unsupported version of the file '.
          'format (found version %s, expected version 4).',

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Open the file and confirm it is a notebook object starting with '{' and containing 'nbformat' and 'cells'
  2. Replace the file with a real notebook exported from Jupyter

Example fix

file.ipynb (before):
"no notebook here"

file.ipynb (after):
{
  "nbformat": 4,
  "nbformat_minor": 5,
  "metadata": {},
  "cells": []
}
Defensive patterns

Strategy: validation

Validate before calling

$data = json_decode($raw, true);
if (!is_array($data)) {
  // root is not an object/list: not a notebook
}

Try / catch

catch Exception and surface 'not a valid notebook object' to the user; offer the raw file view.

Prevention

When it happens

Trigger: A .ipynb file whose JSON root is a scalar — e.g. content '5', '"hello"', or 'true' — which decodes to int/string/bool rather than an array.

Common situations: Plain text or single-value JSON files renamed to .ipynb; API responses pasted into a notebook file; scaffolding scripts writing a scalar placeholder.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/b02ee3540eafb7ff. Report an issue: GitHub.