Skip to content

feat: add get_number_from_path#98

Open
jp4g wants to merge 1 commit into
noir-lang:mainfrom
jp4g:feat-get-number-from-path
Open

feat: add get_number_from_path#98
jp4g wants to merge 1 commit into
noir-lang:mainfrom
jp4g:feat-get-number-from-path

Conversation

@jp4g

@jp4g jp4g commented Apr 22, 2026

Copy link
Copy Markdown

Summary

  • Adds pub fn get_number_from_path mirroring the existing get_string_from_path.
  • No breaking changes, no other API surface touched.

Motivation

When the root JSON is an object, there is currently no public path to extract a numeric value at a root-level (or nested) key:

  • get_number / get_number_unchecked are pub(crate).
  • get_number_from_array / _unchecked are pub but only apply when the root is an array.
  • get_value_from_path returns a JSONValue with pub(crate) fields, so the bytes are unreachable anyway.

This PR closes that gap with the smallest possible change: one new public function, symmetric with get_string_from_path.

Test plan

  • Existing tests pass (nargo test).
  • Usable externally: let n = json.get_number_from_path([key_vec(\"exp\")]).unwrap(); resolves and returns a u64 for a top-level numeric key.

Mirrors the existing pub `get_string_from_path`: walks a chain of object keys
and returns `Option<u64>` from the terminal key. Fills the gap where, with the
root JSON being an object, numeric extraction at a root-level key has no
public entry point (the underlying `get_number` is `pub(crate)`, and
`get_number_from_array` only applies when the root is an array).

No breaking changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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