Skip to content

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

Open
Aditya-9-6 wants to merge 5 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 5 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}");
}

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 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 5.85%

⚠️ 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

⚡ 2 improved benchmarks
❌ 8 regressed benchmarks
✅ 57 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
unicode_jiter_iter 1.2 µs 1.4 µs -15.95%
massive_ints_array_jiter_value 423.9 µs 470.5 µs -9.92%
sentence_jiter_iter 1 µs 1.1 µs -9.76%
unicode_jiter_value 1.3 µs 1.4 µs -8.64%
medium_response_jiter_value 12.7 µs 13.9 µs -8.24%
sentence_jiter_value 1.1 µs 1.2 µs -8.14%
massive_ints_array_jiter_iter 378.7 µs 407.1 µs -6.98%
short_numbers_jiter_value 49.2 µs 52 µs -5.49%
string_array_jiter_value_owned 16.9 µs 15 µs +12.28%
true_array_jiter_value 3.1 µs 2.9 µs +5.35%

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 (8d3febf) with main (9e7d52f)

Open in CodSpeed

@Aditya-9-6
Aditya-9-6 force-pushed the main branch 3 times, most recently from 90aa030 to ec12f4a Compare August 17, 2026 16:01
@Aditya-9-6
Aditya-9-6 force-pushed the main branch 3 times, most recently from 6b6643f to 2574a60 Compare August 24, 2026 11:23
…Value

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread crates/jiter/src/value.rs
Comment thread crates/jiter/tests/main.rs Outdated
Comment thread crates/jiter/src/value.rs
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