Skip to content

feat(value): add ergonomic type checking and accessor methods to JsonValue - #262

Open
Aditya-9-6 wants to merge 3 commits into
pydantic:mainfrom
Aditya-9-6:main
Open

feat(value): add ergonomic type checking and accessor methods to JsonValue#262
Aditya-9-6 wants to merge 3 commits into
pydantic:mainfrom
Aditya-9-6:main

Conversation

@Aditya-9-6

Copy link
Copy Markdown

Motivation

Currently, working with JsonValue in pure Rust code requires matching on JsonValue variants for every access. Adding standard accessor and type checking methods (similar to serde_json::Value) improves developer ergonomics significantly when querying or inspecting parsed JSON data.

Solution

Added the following accessor methods to JsonValue<'j>:

  • Type queries: is_null(), is_boolean(), is_number(), is_int(), is_float(), is_string(), is_array(), is_object()
  • Value accessors: as_bool(), as_i64(), as_f64(), as_str(), as_array(), as_object()
  • Object lookup: get(key: &str) -> Option<&JsonValue<'j>>
let val = JsonValue::parse(json_bytes, true)?;
if let Some(name) = val.get("name").and_then(|v| v.as_str()) {
    println!("Name: {name}");
}

Signed-off-by: Aditya Dahale <aditya.dahale@example.com>
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.12281% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/jiter/src/value.rs 99.12% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Aug 13, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 15.52%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 3 regressed benchmarks
✅ 67 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
massive_ints_array_jiter_iter 564.1 µs 685 µs -17.65%
python_parse_massive_ints_array 1.1 ms 1.4 ms -16.66%
massive_ints_array_jiter_value 743 µs 845.6 µs -12.14%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Aditya-9-6:main (3e307d2) with main (785cf75)

Open in CodSpeed

Aditya Dahale added 2 commits August 16, 2026 16:07
…ive test coverage for JsonValue accessors

Signed-off-by: Aditya Dahale <aditya.dahale@example.com>
Signed-off-by: Aditya Dahale <aditya.dahale@example.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