Skip to content

std/json: export nifcore and make readError public - #3346

Open
seromarin-dev wants to merge 1 commit into
nim-lang:masterfrom
seromarin-dev:json-extensibility
Open

seromarin-dev wants to merge 1 commit into
nim-lang:masterfrom
seromarin-dev:json-extensibility

Conversation

@seromarin-dev

Copy link
Copy Markdown
Contributor

Fixes #3345.

std/json is a thin layer over nifcore's flat token buffer, but it kept the substrate private. This re-exports nifcore (the same way parsejson is already re-exported), so an extension package can name TokenBuf and use its builder operations through std/json alone.

It also makes readError public on JsonOptions and JsonTree, so a typed reader built outside std/json can report why it raised through the existing errorMsg channel.

Tests:

  • hastur test tests/nimony/stdlib/tjson.nim
  • hastur test tests/nimony/stdlib/tparsejson.nim
  • hastur test tests/nimony/stdlib/tall.nim

std/json is a thin layer over nifcore's flat token buffer, but it kept the substrate private: an extension package could see JsonTree.buf yet could not name TokenBuf or call its builder operations. Re-export nifcore, the same way parsejson is already re-exported.

Also expose readError on JsonOptions and JsonTree so a typed reader built outside std/json can report why it raised through the existing errorMsg channel.
Comment thread lib/std/json.nim
import std / [parsejson, streams, parseutils, assertions, formatfloat, syncio, typetraits, tables, opt]
import ../../src/lib/nifcore

export nifcore # the flat-buffer model is std/json's public substrate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is the correct way to do it. I'm open to suggestions 🙏

@seromarin-dev
seromarin-dev marked this pull request as draft December 5, 2026 11:36
@seromarin-dev
seromarin-dev marked this pull request as ready for review December 5, 2026 18:39
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.

std/json: expose the NIF substrate and readError for extension packages

1 participant