jsonify 0.2.0

Simple struct to JSON library for Rust
Documentation
  • Coverage
  • 75%
    3 out of 4 items documented3 out of 3 items with examples
  • Size
  • Source code size: 3.32 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.05 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • owoNUB
jsonify-0.2.0 has been yanked.

JSONify

A simple library to convert structs to JSON.

Quick Example

#[macro_use] extern crate jsonify;

use jsonify::Serializable;

struct Foo {
    bar: String,
    baz: i32
}

impl Serializable for Foo {
    fn serialize(&self) -> String {
        json!(
            bar => self.bar,
            baz => self.baz
        )
    }
}

fn main() {
    let foo = Foo { bar: "Hello!".to_string(), baz: 30 };

    println!("{}", foo.serialize()); // Output: {"bar": "Hello!", "baz": 30}
}

What is going on here?

Import JSONify and Serializable trait

#[macro_use] extern crate jsonify;

use jsonify::Serializable;

Create struct Foo

struct Foo {
    bar: String,
    baz: i32
}

Implement Serializable trait

impl Serializable for Foo {
    fn serialize(&self) -> String {
        // ...
    }
}

Calls json! macro to create JSON string

/*
    Usage:
    json!(
        key => value,
        key2 => value2
    )
*/
json!(
    bar => self.bar,
    baz => self.baz
)

Create instance of Foo and serialize it

fn main() {
    let foo = Foo { bar: "Hello!".to_string(), baz: 30 };

    println!("{}", foo.serialize()); // Output: {"bar": "Hello!", "baz": 30}
}