#json #serialization #web #json-object

jrd

json resource descriptor, as specified by https://www.packetizer.com/json/jrd/

1 unstable release

0.1.0 Mar 21, 2024

#1879 in Encoding

MIT license

14KB

jrd

json resource descriptor, as specified by https://www.packetizer.com/json/jrd/

this tiny crate provides a struct representation for Json Resource Descriptors, with serde traits derived

get more information on its usage on docs.rs

why

this crate is tiny and does very little, mostly piggy-backing from Packetizer's documentation

i found myself writing this and the docs for myself while working on a project, to have better hints around JRDs, so I thought others might find it useful and decided to share it publicly


lib.rs:

JRD

from Packetizer:

The JSON Resource Descriptor (JRD) is a simple JSON object that describes a "resource" on the Internet, where a "resource" is any entity on the Internet that is identified via a URI or IRI. For example, a person's account URI (e.g., acct:bob@example.com) is a resource. So are all web URIs (e.g., https://www.packetizer.com/).

The JSON Resource Descriptor, originally introduced in RFC 6415 and based on the Extensible Resource Descriptor (XRD) format, was adopted for use in the WebFinger protocol, though its use is not restricted to WebFinger or RFC 6415.

This tiny crate provides a struct representation of JRDs, [JsonResourceDescriptor], together with serde::Serialize and serde::Deserialize implementations.

All documentation is copied as-is from packetizer.com.

usage

let jrd_string = r#"{
  "subject": "acct:paulej@packetizer.com",
  "properties": {
    "http://packetizer.com/ns/name": "Paul E. Jones"
  },
  "links": [
    {
      "rel": "http://webfinger.net/rel/profile-page",
      "href": "http://www.packetizer.com/people/paulej/"
    },
    {
      "rel": "http://packetizer.com/rel/blog",
      "type": "text/html",
      "href": "http://www.packetizer.com/people/paulej/blog/",
      "titles": {
        "en-us": "Paul E. Jones' Blog"
      }
    }
  ]
}"#;

let jrd_struct = jrd::JsonResourceDescriptor {
  subject: "acct:paulej@packetizer.com".into(),
  aliases: Vec::new(),
  properties: [("http://packetizer.com/ns/name".to_string(), "Paul E. Jones".to_string())].into(),
  expires: None,
  links: vec![
    jrd::JsonResourceDescriptorLink {
      rel: "http://webfinger.net/rel/profile-page".into(),
      href: Some("http://www.packetizer.com/people/paulej/".into()),
      link_type: None,
      titles: jrd::Map::default(),
      properties: jrd::Map::default(),
    },
    jrd::JsonResourceDescriptorLink {
      rel: "http://packetizer.com/rel/blog".into(),
      href: Some("http://www.packetizer.com/people/paulej/blog/".into()),
      link_type: Some("text/html".into()),
      titles: [("en-us".to_string(), "Paul E. Jones' Blog".to_string())].into(),
      properties: jrd::Map::default(),
    },
  ],
};

// deserialize
assert_eq!(serde_json::from_str::<jrd::JsonResourceDescriptor>(jrd_string).unwrap(), jrd_struct);

// serialize
assert_eq!(serde_json::to_string_pretty(&jrd_struct).unwrap(), jrd_string)

Dependencies

~1.3–2.1MB
~40K SLoC