Output identity as JSON.
(&self, identity: &atomic_identity::Identity, context: Option<&IdentityUsage>)
| 155 | |
| 156 | /// Output identity as JSON. |
| 157 | fn output_json(&self, identity: &atomic_identity::Identity, context: Option<&IdentityUsage>) { |
| 158 | use serde_json::json; |
| 159 | |
| 160 | let mut obj = json!({ |
| 161 | "name": identity.name, |
| 162 | "id": identity.id.to_base32(), |
| 163 | "type": super::format_identity_type(&identity.identity_type), |
| 164 | "usage": super::format_usage(&identity.usage), |
| 165 | "public_key": identity.public_key_base32(), |
| 166 | }); |
| 167 | |
| 168 | if let Some(email) = &identity.email { |
| 169 | obj["email"] = json!(email); |
| 170 | } |
| 171 | |
| 172 | if let Some(description) = &identity.metadata.description { |
| 173 | obj["description"] = json!(description); |
| 174 | } |
| 175 | |
| 176 | if let Some(delegator) = &identity.delegated_by { |
| 177 | obj["delegated_by"] = json!(delegator.to_base32()); |
| 178 | } |
| 179 | |
| 180 | if let Some(usage) = context { |
| 181 | obj["context"] = json!(super::format_usage(usage)); |
| 182 | } |
| 183 | |
| 184 | println!("{}", serde_json::to_string_pretty(&obj).unwrap()); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | // Tests |