Running on Linux Mint, serde_json
seems unable to use it's own macros. The json!
macro fails to work on Linux Mint, but works just fine on Win11. I was trying to serialize some data and couldn't get the example from the docs to work, and had an LLM generate a code snippet to test. After checking my dependencies for a while, I was unable to resolve the issue. I booted into Windows to test if it was an OS issue, and lo and behold it appears to be.
Code snippet if you would like to test:
use serde::{Serialize, Deserialize};
use serde_json::{json, Value};
#[derive(Serialize, Deserialize)]
struct Person {
name: String,
age: u32,
}
fn main() -> Result<(), serde_json::Error> {
// Create a vector of Person structs
let people = vec![
Person { name: "Alice".to_string(), age: 30 },
Person { name: "Bob".to_string(), age: 25 },
Person { name: "Charlie".to_string(), age: 35 },
];
// Create a vector to hold the JSON Values
let mut json_objects: Vec<Value> = Vec::new();
// Iterate over the people vector and add each serialized Person to json_objects
for person in people {
let person_value = serde_json::to_value(&person)?;
json_objects.push(person_value);
}
// Create the final JSON object with the "people" key containing the array of objects
let final_json = json!({
"people": json_objects
});
println!("Serialized JSON: {}", final_json.to_string());
Ok(())
}
The actual error is this:
error: cannot find macro `json_internal` in this scope
--> src/main.rs:28:22
|
28 | let final_json = json!({
| ______________________^
29 | | "people": json_objects
30 | | });
| |______^
|
= note: this error originates in the macro `json` (in Nightly builds, run with -Z macro-backtrace for more info)
Any ideas how to fix this? I've been seeing massive performance gains on my original script (200ms execution time vs 50ms) since switching from Windows to Linux, and would hate to have to switch back simply to make data parsing easier.
Any suggestions?