serde-json Questions
1
Solved
I want to deserialize the following struct using serde_json. The parent_id field should accept an integer or a null, but I want it to return an error if the field is missing.
#[derive(Debug, Serial...
Submultiple asked 9/7 at 9:51
5
Solved
I'm writing a crate that interfaces with a JSON web API. One endpoint usually returns responses of the form { "key": ["value1", "value2"] }, but sometimes there's only one value for the key, and th...
Translation asked 14/12, 2016 at 19:53
3
Solved
I have a 5GB JSON file which is an array of objects with fixed structure:
[
{
"first": "John",
"last": "Doe",
"email": "[email protec...
Gar asked 3/8, 2021 at 18:31
3
Solved
I'm writing a function that returns a serde_json::Value upon success (and failure). Previously in Rust I have been omitting the semicolon to return data from a function, like in the code example be...
Neume asked 23/11, 2019 at 23:52
2
Solved
Using serde_json, I have JSON objects with Strings that I need to convert to floats. I've stumbled upon a custom deserializer solution, but it seems like a hack. Here is a working playground exampl...
Lubra asked 29/6, 2017 at 23:12
3
Solved
The serde_json::to_string() function will generate a string which may include null for an Option<T>, or 0 for a u32. This makes the output larger, so I want to ignore these sorts of values.
...
Fineberg asked 23/12, 2018 at 1:49
2
Solved
I have to deserialize JSON blobs where in some places the absence of an entire object is encoded as an object with the same structure but all of its fields set to default values (empty strings and ...
Err asked 2/10, 2018 at 15:10
4
Solved
I want to serialize a HashMap with structs as keys:
use serde::{Deserialize, Serialize}; // 1.0.68
use std::collections::HashMap;
fn main() {
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq...
Cutis asked 11/7, 2018 at 3:40
3
Solved
I have a JSON structure that looks like this:
{ "type": "suite", "event": "started", "test_count": 1 }
I want to deserialize into these structs:
#[derive(Debug, Deserialize)]
enum ResultType {
...
Digiacomo asked 4/12, 2019 at 0:37
1
I want to make a Serde struct that is capable of being deserialized from either borrowed data (serde_json::from_str) or owned data (serde_json::from_reader). I have read Understanding deserializer ...
Durango asked 1/8, 2020 at 4:0
1
Solved
Below is a non-functioning code example:
use serde_json::json;
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Model<T>
where
T: DeserializeOwned,
{
pub id: i32,
pub info: Opti...
Shavonda asked 19/1, 2022 at 16:16
2
I want to print the name of each contact in the object deep down the hierarchy. The contact object may not have the exact same number of fields every time to make a suitable structure. How can I ac...
Sweetbrier asked 17/8, 2018 at 16:1
1
Solved
I have this struct that has a field containing type Option<serde_json::Value>
I want to be able to store any object( i.e. object created by any struct) in that field. The current approach I'm...
Soporific asked 31/7, 2021 at 14:12
2
I'm trying to get the name of an enum variant as the string serde would expect/create. For example, say I have the following enum:
#[derive(Serialize, Deserialize)]
#[serde(rename_all="camelCa...
Ignatia asked 22/4, 2021 at 15:7
1
Solved
I'm using the reqwest (version 0.10.4) crate for the HTTP calls in my Rust application but can't find any examples of how to handle APIs calls that could return more than one possible response body...
Photosynthesis asked 25/4, 2020 at 16:23
1
Solved
What I mean is that if 2 objects overlaps on some of the attributes is there a way to try to match all of them?
For example:
use serde::{Serialize, Deserialize};
use serde_json; // 1.0.47; // 1.0....
Hers asked 2/3, 2020 at 12:42
1
Solved
I need to build a json object at runtime. For now, just a simple {"key": "stringvalue"} object. But each key/val pair must be added in a loop.
This seems really simple/basic, but I didn't find any...
Husch asked 26/11, 2019 at 9:7
1
borrowed value does not live long enough when use generic lifecycle。
fn get<'a, T>(&self, key: &[u8]) -> Result<Option<T>>
where
T: Deserialize<'a>,
{
match se...
Lakendra asked 5/9, 2019 at 2:23
1
Solved
I'm quite a beginner in Rust, and just have encountered a problem with parsing JSON files. I tried using serde_json for the task. I know how to parse an ASCII file as a string, and how to parse its...
Phyllotaxis asked 30/7, 2019 at 21:12
1
I am trying to use Serde to deserialize JSON (serde-json) and XML (serde-xml-rs) files based on the following struct:
use serde_derive::Deserialize;
#[derive(Debug, Clone, PartialEq, Deserialize)...
Streaky asked 11/1, 2019 at 15:56
3
Solved
I have two JSON files:
JSON 1
{
"title": "This is a title",
"person" : {
"firstName" : "John",
"lastName" : "Doe"
},
"cities":[ "london", "paris" ]
}
JSON 2
{
"title": "This is another ...
Spathose asked 2/11, 2017 at 8:40
1
Solved
I am trying to serialize an enum to a JSON string. I implemented Serialize trait for my enum as it is described in the docs, but I always get {"offset":{"Int":0}} instead of the desired {"offset":0...
Calica asked 27/8, 2018 at 7:43
1
I am trying to poll the GitHub API for issues and print them out. To do so, I need to deserialize a nested JSON structure that I receive from a cURL GET request.
I am trying to get the url for all...
Mooned asked 3/2, 2018 at 9:8
1
Solved
I'm developing an API wrapper and I'm having some troubles with the deserialization of an empty JSON object.
The API returns this JSON object. Mind the empty object at entities:
{
"object": "pa...
Ileanaileane asked 28/10, 2017 at 18:29
1
Solved
I am stuck, below is the JSON which I am receiving:
{
"BCH": {
"aclass": "currency",
"altname": "BCH",
"decimals": 10,
"display_decimals": 5
}
}
I am bit confused on how my struct should l...
Estevez asked 6/9, 2017 at 11:44
1 Next >
© 2022 - 2024 — McMap. All rights reserved.