feat(stdlib): add @acton/json decoder module#1097
Open
zakrad wants to merge 1 commit into
Open
Conversation
Adds a small read-only JSON decoder to the Acton stdlib, complementing fs.readFile (which loads a JSON file as a string but cannot parse it). Values are addressed with a JSON Pointer (RFC 6901). getInt/getString/ getBool return null on invalid JSON, a missing path, or a type mismatch (consistent with @acton/env); exists reports whether a pointer resolves. getInt also accepts quoted decimal/0x-hex strings to carry full 257-bit integers losslessly. Host handlers (EXTCALL ids 300-303) are added under src/ffi/json.rs and registered in src/ffi/mod.rs; the Tolk surface is in lib/json.tolk. Closes ton-blockchain#1096
✅ Deploy Preview for acton-staging ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a small, read-only JSON decoder to the Acton stdlib as
@acton/json. It isthe natural companion to
fs.readFile, which can load a JSON file as astringbut offers no way to parse it.
Implements the proposal in #1096.
API
Values are addressed with a JSON Pointer (RFC 6901), e.g.
/token/decimalsor/items/0:Design
@acton/env: invalid JSON, a missing path, or atype mismatch all return
null, so??can supply a default.serde_json's built-inValue::pointer()— nocustom path parser.
getIntaccepts a JSON integer, or a JSON string holding a decimal/0x-hexinteger. Floats return
null. Bare numbers beyond 64 bits are not reliablyrepresentable, so they return
nullrather than a lossy value; encode suchvalues as JSON strings to carry full 257-bit integers losslessly.
getBooldistinguishes a presentfalse(returned asfalse) from anabsent/non-boolean value (
null).Implementation
src/ffi/json.rs(EXTCALL ids300–303), registered insrc/ffi/mod.rs, following the existingenv/fspattern.lib/json.tolk.serde_json, already a dependency; no new crates.Testing
tests/integration/test_runner/json_reads_typed_values_by_pointer_tests.rscover numbers/strings/hex/floats, nested paths, array indices, present-
falsevs
null, missing paths, and invalid JSON.just fmt-check,cargo clippy --workspace --all-targets --all-features -- -D warnings,typos,acton docgen --check,acton fmt --check,acton check, andacton test(native stdlib suite).Docs
Generated
docs/content/docs/standard_library/json.mdxand the overview indexvia
acton docgen;docgen --checkpasses.Closes #1096
Note
Prepared with the help of an AI coding assistant; reviewed and locally verified by the author before submission.