Skip to content

[Feature] Network Inspector’s line-delimited JSON parsing logic does not handle blank lines correctly #3067

Open

Description

@ZhiyanJia

Description

Network Inspector supports parsing multiple independent JSON objects separated by newlines in request and response bodies.

However, the line-delimited parsing fallback fails when:

  • Blank or whitespace-only lines appear between JSON objects.
  • The body ends with an LF or CRLF newline.

Without these blank lines or trailing newlines, the same JSON objects are successfully parsed into an array.

Expected behavior

The line-delimited parsing fallback should ignore blank and whitespace-only lines, including those produced by trailing newlines, and return the parsed objects as an array:

[
    { "a": 1 },
    { "b": 2 }
]

Malformed JSON on a nonblank line should still produce an error.

Actual behavior

Blank lines or trailing newlines cause the line-delimited parsing fallback to throw a SyntaxError.

The outer formatter catches and logs the exception. If no subsequent formatter succeeds, the body is returned as raw text instead of a structured array.

Affected components

The issue affects two formatters in Network Inspector:

  • JSON formatter: formats request and response bodies.
  • GraphQL response formatter: formats response bodies.

A single valid JSON document containing formatting whitespace or a trailing newline is not affected.

Impact

Affected bodies lose their structured representation and fall back to raw-text output, preventing inspection as an object array.

The original body remains available, and the network request itself is unaffected.

Suggested fix

Handle blank and whitespace-only lines consistently in both line-delimited parsing fallbacks before parsing individual entries.

Add regression tests covering:

  • Blank lines between JSON objects.
  • Whitespace-only lines between JSON objects.
  • Trailing LF and CRLF.
  • Multiple JSON objects without blank lines.
  • A single valid, pretty-printed JSON document with a trailing newline.
  • Malformed JSON on a nonblank line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions