Serde: flatten, but also prepend field name

Hi everyone, I want to flatten, because I don't want the JSON syntax of a nested object. but I do want it to prepend the field name. e.g.

use serde::*;
use serde_json::*;

struct Bar {
    a: &'static str,
    b: &'static str,

struct Baz {
    c: &'static str,
    d: &'static str,

struct Foo {
    bar: Bar,
    baz: Baz,

fn main() {
    let foo = Foo {
        bar: Bar {
            a: "a",
            b: "b",
        baz: Baz {
            c: "c",
            d: "d",
    println!("{}", serde_json::to_string(&foo).unwrap());



But I want:



Thanks to the Rust Discord, looks like this is the answer: with_prefix in serde_with - Rust

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.