Skip to content

src: create lazy json parser#61855

Draft
araujogui wants to merge 1 commit intonodejs:mainfrom
araujogui:lazy-json-parser
Draft

src: create lazy json parser#61855
araujogui wants to merge 1 commit intonodejs:mainfrom
araujogui:lazy-json-parser

Conversation

@araujogui
Copy link
Member

No description provided.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/gyp
  • @nodejs/loaders
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Feb 16, 2026
@JakobJingleheimer
Copy link
Member

Is this related to #61641 ?

@araujogui
Copy link
Member Author

Is this related to #61641 ?

Yeah, I decided to pivot. Since full JSON materialization is likely a performance bottleneck, I’m implementing a lazy JSON parser instead.

test('compound root array returns document with type "array"', (t) => {
const parser = new Parser();
const doc = parser.parse('[1, 2, 3]');
t.assert.strictEqual(doc.root().type(), 'array');
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't return string from this. This would be extremely slow. We can use an enum of numeric values called JSONType, and to .type() == JSONType.Array

require('../common');

const { test, describe } = require('node:test');
const { Parser } = require('node:json_parser');
Copy link
Member

Choose a reason for hiding this comment

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

Why limit the module name to only parser?

Suggested change
const { Parser } = require('node:json_parser');
const { JSONParser } = require('node:json');

Copy link
Member

@anonrig anonrig left a comment

Choose a reason for hiding this comment

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

  • Docs are missing.
  • Tests handling each edge case (errors) are missing

Copy link
Member

@RafaelGSS RafaelGSS left a comment

Choose a reason for hiding this comment

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

As I said in the OpenJS Slack, I don't see value in it on the core instead of a userland module.

Considering there's no internal usage of it yet, it's just another module to handle fixes and security patches.

@araujogui
Copy link
Member Author

As I said in the OpenJS Slack, I don't see value in it on the core instead of a userland module.

Considering there's no internal usage of it yet, it's just another module to handle fixes and security patches.

Just curious, what’s the line of reasoning for deciding whether something should be part of the core or not? Is that documented somewhere, or is it more of a case-by-case consensus?

@anonrig anonrig requested a review from mcollina February 17, 2026 22:59
@araujogui
Copy link
Member Author

Just to be clear: this PR isn’t ready yet. I opened it to gather feedback before moving too far ahead.

@jsumners-nr
Copy link

As I said in the OpenJS Slack, I don't see value in it on the core instead of a userland module.
Considering there's no internal usage of it yet, it's just another module to handle fixes and security patches.

Just curious, what’s the line of reasoning for deciding whether something should be part of the core or not? Is that documented somewhere, or is it more of a case-by-case consensus?

In this sort of case, I'd say that it is due to the fact that the vast majority of people rely on the JSON built-in and would have to explicitly decide to use node:json and there isn't a clamor for a JSON replacement in core that I am aware of. But I'm just guessing.

@RafaelGSS
Copy link
Member

Just curious, what’s the line of reasoning for deciding whether something should be part of the core or not? Is that documented somewhere, or is it more of a case-by-case consensus?

That's actually a good question, and I have been discussing with TSC a few times to clarify somewhere what makes a module prone to be on nodejs built-in and what not. Unfortunately, that's not easy to define and change from time to time - for instance, most modules that are now on Node.js built-in wouldn't be here if they were proposed 5 years ago.

I concur with @jsumners-nr on it. We don't have evidence that the community needs that, nor do we have a plan to use that on Node.js internals, for instance, to improve performance somehow. Usually, modules that get inserted on Node.js built-in follow one or more of these bullet points:

  • The community uses it widely, and the userland packages aren't being actively maintained, which poses a significant security risk.
  • We currently have an internal usage for that, and we are just exposing the module, so technically, we won't add more maintenance burden on it.
  • There are a group of folks that volunteer to maintain the module

Please, have in mind that more modules often mean more maintenance and more attack surface. We are currently overwhelmed with security reports, and adding a new module without matching the above bullet points will only increase the maintenance on Node.js members and the amount of security reports the security triage team needs to deal with.

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

Labels

lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

Comments