Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native JSONC parsing #12402

Open
2 tasks done
aster-void opened this issue Feb 3, 2025 · 3 comments
Open
2 tasks done

native JSONC parsing #12402

aster-void opened this issue Feb 3, 2025 · 3 comments
Labels
feature Feature request or proposal

Comments

@aster-void
Copy link

aster-void commented Feb 3, 2025

Is your feature request related to a problem

nix can't natively parse JSONC.

more specifically, I had to manually remove trailing commas from bun.lock to parse it into nix object.

Proposed solution

add builtin function builtins.fromJSONC

JSONC doesn't have "one universal standard", but it's generally assumed to be JSON superset with C-style comments (// and /* */) and trailing commas allowed (but not required)

Alternative solutions

  1. add support for JSON5, which is superset of JSONC and has a universal standard https://json5.org/
  2. use some package from nixpkgs to parse it (IFD)
  3. manually remove comments and trailing commas from JSONC to then parse with builtins.fromJSON

Additional context

Checklist


Add 👍 to issues you find important.

@aster-void aster-void added the feature Feature request or proposal label Feb 3, 2025
@Eveeifyeve
Copy link

I would be happy to make a pr that adds builtins.fromJson ./jsonfile.jsonc {supportJsonc = true}; but I think I would need to get approval.

CC @Ericson2314

@grahamc
Copy link
Member

grahamc commented Feb 3, 2025

Probably json5 would be a better approach?

@Ericson2314
Copy link
Member

I can't speak for the rest of the Nix team, but I am rather uninterested in adding misc new builtins until we have a plan for versioning the language. We need to eat our vegetables before moving on to dessert! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal
Projects
None yet
Development

No branches or pull requests

4 participants