Questions tagged [serde]

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

Site

Repository

crates.io

839 questions
0
votes
0 answers

How can I deserialize a value into a struct with that value and a PhantomData in Serde?

I need some extra type information on a URL, so I've created a UrlWithPhantomdata struct with a value field for the URL and a PhantomData field. How can I deserialize a string into this struct with Serde? More specifically, given this JSON…
konstin
  • 476
  • 7
  • 16
0
votes
1 answer

How can I do key-agnostic deserialization of JSON objects?

I am working with a less than ideal API that doesn't follow any rigid standard for sending data. Each payload comes with some payload info before the JSON, followed by the actual data inside which can be a single string or several fields. As it…
ozdrgnaDiies
  • 1,909
  • 1
  • 19
  • 34
0
votes
1 answer

How to deserialize two different structures and file formats using toml-rs and serde_derive?

I am using toml-rs and serde_derive to deserialize TOML files my app uses to describe data structures. I have everything working with my first data structure which corresponds to one TOML file definition with obligatory and optional fields. Now I…
Andrew Mackenzie
  • 5,477
  • 5
  • 48
  • 70
0
votes
1 answer

What's the equivalent of rustc_serialize::Json in serde?

Since the serde library is going to become a replacement of rustc_serialize, I'm trying to refactor my library to work with it. I can't figure out what the corresponding type of rustc_serialize::Json is. Suppose, I have a method which accepts…
user266003
0
votes
1 answer

Selecting a subset of keys from a JSON array

I am trying to parse a JSON API that spits out output like this: { "message": "success", "number": 6, "people": [ { "craft": "ISS", "name": "Gennady Padalka" }, { "craft": "ISS", "name": "Mikhail…
CuriOne
  • 103
  • 3
  • 8
-1
votes
1 answer

Can a struct contain a key consisting only of digits?

I have a DB response containing my ID field, which I need, like this: { ... other fields "0000": "9" } So I want to make a struct to parse this response to and it should be like: #[derive(Serialize, Deserialize, Debug)] struct PostResponse { …
-1
votes
1 answer

How do I solve this error for Serde Deserialize?

Dependencies: serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" My code: use serde::{Deserialize, Serialize}; use serde_json::{Result, Value}; use std::collections::HashMap; use serde::de::Error; #[derive(Debug)] pub struct Log…
dwldladas
  • 9
  • 2
-1
votes
1 answer

How to deserialize Option where T has a custom deserializer?

I want to create deserialize function for Option where I already have a custom deserializer for T and I want to use that deserializer for T, when deserializing Option: pub fn deserialize(deserializer: D) -> Result { …
porton
  • 5,214
  • 11
  • 47
  • 95
-1
votes
1 answer

How to deserialize json to enum in rust?

I have string "040000" and I want to get a variant of this enum: #[derive(Serialize, Deserialize, PartialEq, Debug, Clone, JsonSchema)] pub enum GitCreateTreeRequestMode { #[serde(rename = "040000")] SubdirectoryTree, #[serde(rename =…
FreePhoenix888
  • 4,510
  • 3
  • 13
  • 22
-1
votes
1 answer

Deserialize data error using serde in Rust

I have three structs A, B and C that are being fed to a method process_data() as a list of JSON. All the three structs are serde serializable/deserializable. They are defined below as follows:- #[derive(Serialize, Deserialize)] struct A { pub a:…
blueStack453
  • 59
  • 1
  • 5
-1
votes
1 answer

Handling different ways to represent null in serde

I'm writing a client library around this REST server. Octoprint (A server to manage a 3d printer), to be precise. Here's one of the types i'm working with: #[derive(Serialize, Deserialize, Debug)] pub struct JobInfo { /// The file that is the…
Brandon Piña
  • 614
  • 1
  • 6
  • 20
-1
votes
1 answer

Serialize HashSet of enum variants as a regular HashMap using rocket serde

#[derive(Deserialize, Serialize)] enum En { A(i32), B(String) } #[derive(Deserialize, Serialize)] struct Data { data: Mutex> } When using this structure, serializing the struct outputs something like {"data": [{"A": 0},…
Ontley
  • 1
  • 5
-1
votes
1 answer

How to deserialize a json object into rust understandable code using enums?

I need to deserialize ( and later on serialize ) a piece of data that has this type of a structure : { "type": "TypeApplication", "val": { "con": { "type": "TypeConstructor", "val": [ "Builtin", "Record" ] …
unownone
  • 56
  • 1
  • 6
-1
votes
1 answer

Serde Deserilize with keyword tag

The following code snippet is how I use serde::Deserialize; #[derive(Debug, Deserialize)] struct OuterStruct{ name: String, value: i64, inner: Wrapper, } #[derive(Debug, Deserialize)] struct structA{ #[serde(rename = "type")] ttype:…
Bryant
  • 1
  • 1
-1
votes
1 answer

Access JSON array in serde_json::Value

I have some JSON formatted like this: [ { "name": "jsonvalue" } ] And I want to print it like println!("{:?}", json["name"]);. How do I access a JSON array from a serde_json::Value? I would like to not have to use more variables to…
salmon
  • 31
  • 4
1 2 3
55
56