Skip to content

Support JSON.jl v1 - #329

Draft
fromelicks wants to merge 1 commit into
JuliaGizmos:masterfrom
fromelicks:json-1-compat
Draft

fromelicks wants to merge 1 commit into
JuliaGizmos:masterfrom
fromelicks:json-1-compat

Conversation

@fromelicks

@fromelicks fromelicks commented Sep 7, 2026 •

Copy link
Copy Markdown

Unlike #328 this PR works with JSExpr.jl v0.5.

JSON.jl v1 changes three things Blink depends on:

  • JSON.parse(::IO) no longer parses a single value off a stream and leaves the rest in the buffer; it reads through to EOF. Electron wrote callback results back-to-back with no delimiter, so on a live socket the read loop would simply block. Messages are now newline-delimited in both directions, matching the framing Blink already used when sending, and recvmsg reads a line at a time;
  • json is no longer exported, only public;
  • Non-finite floats throw instead of being written as null, and allownan=true emits NaN/Infinity, which the browser's JSON parsing rejects. Blink serializes arbitrary user data, so a JSONStyle keeps the old null behaviour.

Parsed messages also materialize as JSON.Object rather than Dict under v1. They are handed straight to callbacks registered via handle, so jsonparse keeps producing Dict{String, Any} rather than breaking every ::Dict signature downstream.

The version-dependent spellings live in src/jsoncompat.jl; JSON.jl 0.21 remains supported.

This PR depends on JuliaGizmos/WebIO.jl#521 and JuliaGizmos/JSExpr.jl#49.

Comment thread src/AtomShell/process.jl
Comment on lines +109 to +119
sendmsg(io::IO, m) = (jsonprint(io, m); println(io))

function recvmsg(io::IO)
line = readline(io)
if isempty(line)
return nothing # EOF, or a truncated read during shutdown
end
return jsonparse(line)
end

msg(shell::Electron, m) = sendmsg(shell.sock, m)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The framing is explicit in both directions because JSON.jl >= 1 dropped the ability to parse a single value off a stream and leave the remainder in the buffer: JSON.parse(::IO) now reads through to EOF, which on a live socket would simply block. Reading one line at a time keeps a message boundary that does not depend on the parser.

JSON.jl v1 changes three things Blink depends on:

  - `JSON.parse(::IO)` no longer parses a single value off a stream and
    leaves the rest in the buffer; it reads through to EOF. Electron
    wrote callback results back-to-back with no delimiter, so on a live
    socket
    the read loop would simply block. Messages are now newline-delimited
    in both directions, matching the framing Blink already used when
    sending, and `recvmsg` reads a line at a time;
  - `json` is no longer exported, only `public`;
  - Non-finite floats throw instead of being written as `null`, and
    `allownan=true` emits `NaN`/`Infinity`, which the browser's JSON
    parsing rejects. Blink serializes arbitrary user data, so a
    `JSONStyle` keeps the old `null` behaviour.

Parsed messages also materialize as `JSON.Object` rather than `Dict`
under v1. They are handed straight to callbacks registered via `handle`,
so `jsonparse` keeps producing `Dict{String, Any}` rather than breaking
every `::Dict` signature downstream.

The version-dependent spellings live in `src/jsoncompat.jl`; JSON.jl
0.21 remains supported.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant