Questions tagged [serde-json]

A Rust library for parsing and generating the JSON (JavaScript Object Notation) file format.

A Rust library for parsing and generating the JSON (JavaScript Object Notation) file format. It is built upon Serde, a high performance generic serialization framework.

https://github.com/serde-rs/json

139 questions
0
votes
1 answer

Rust complaining about lifetime on the method I am writing

I am struggling to learn Rust with his lifetime. So I am making the method bellow in a web client wrapper. pub async fn get_as_bytes( &self, url: &str, headers: Option, ) -> Result> { …
0
votes
1 answer

Deserializing a String with into_serde makes the app panick

With a friend of mine, we're trying to use the serde_json crate to deserialize some message sent by a WebSocket. We are having a specific error, and we managed to recreate it with the following snippet of code: use serde::{Deserialize,…
nugetchar
  • 172
  • 1
  • 3
  • 17
0
votes
1 answer

Deserializing JSON with multiple possible values with rust

So i am writing a program in Rust (which I am very new to), that reads a json configuration file and does some stuff depending on the input. I have managed to parse the json successfully using serde_json. The next thing i want to allow the user to…
Pasteta
  • 11
  • 3
0
votes
1 answer

How to modify a string inside a serde_json::Value::String?

I have a serde_json::Value containing a string that I want to modify, if possible without cloning the string. I would imagine you would do it like this: let mut value = Value::String("Hello world".to_string()); let mut string =…
Anders
  • 8,307
  • 9
  • 56
  • 88
0
votes
0 answers

How can I deserialize a single field from an array of objects with serde_json?

I have JSON where a key has an array of objects and I'm only interested in one of the strings within that: { "actors": [{ "name": "Bob", "foo": "bar" }, { "name": "Jim", "foo": "baz" }], "fruits": [{ …
SuperWig
  • 155
  • 3
  • 14
0
votes
1 answer

serder_json heserialize map with value being Number or boolean or String

I've been trying to deserialize a JSON containing an object which values can only be a String, a Boolean or a Number. Here is the code I use for that: use serde::{Deserialize, Serialize}; use serde_json::Number; use…
Jeremie
  • 378
  • 1
  • 3
  • 15
0
votes
2 answers

How to set desired return type in match structure?

In the example in the crate documentation of serde_json (parse JSON into a Rust struct), error handling is omitted: use serde::{Deserialize, Serialize}; use serde_json::Result; #[derive(Serialize, Deserialize)] struct Person { name: String, …
user1497298
  • 121
  • 5
0
votes
1 answer

Serde_json serialize to_string with a generic

I'm trying to serialize the params paramter of the send method. fn send(method: &str, params: T) -> () { println!("{:?}", serde_json::to_string(¶ms)); // Rest of actual code that works with 'method' and 'params' } fn main() { …
Nastezz
  • 3
  • 6
0
votes
1 answer

Parsing JSON from an API Result

I'm using RUST and Reqwest to call the following Response from an…
simwilso
  • 23
  • 6
0
votes
2 answers

Deserializing a Claims field to string returns additional characters

I need to deserialize the following payload, in particular the aud field from a JSON object: claims: Claims { aud: One("CBr3zBlrKBbwmxOAM1avZQ=="), // 24 len // ... } claims::aud is an Aud enum: #[derive(Debug, Serialize, Deserialize,…
Alex
  • 367
  • 2
  • 4
  • 14
0
votes
3 answers

How to efficiently extract a portion of JSON as a Vec without intermediate structs?

I have JSON content where, deeply nested, there is an array of numbers I want to extract. I'd like to not create the intermediate structs, so I tried the following: ... get f let json = serde_json::from_reader::<_, serde_json::Value>(f)?; let xs:…
Listerone
  • 1,381
  • 1
  • 11
  • 25
0
votes
1 answer

JSON escape quotes on value before deserializing

I have a server written in Rust, this server gets a request in JSON, the JSON the server is getting is a string and sometimes users write quotes inside the value. For example when making a new forum thread. The only thing I really need to do is to…
Tomdrc1
  • 65
  • 1
  • 8
0
votes
2 answers

How can I return something meaningful from a generic function if there is nothing to return?

I'm building a library in Rust that has a send method that performs HTTP requests against a local RPC server using reqwest. This method returns a generic type R in a Result where R: DeserializeOwned. After making the correct types for every…
n41r0j
  • 143
  • 2
  • 9
0
votes
0 answers

Cannot deserialize with Serde: the `?` operator can only be used in a function that returns `Result`

I'm trying to deserialize a json string to a struct but I'm having trouble with getting it to work. All I want to do is print out the status and or result of the first one to match run["meta"]["username"] against a given username. However despite…
Thermatix
  • 2,757
  • 21
  • 51
0
votes
1 answer

Mismatched types when trying to parse JSON from curl with serde_json

I've got JSON output from an API for open WIFI which I want to put into a database. The data is in this form. I already got the information via curl: let mut easy = Easy::new(); easy.url("https://map.freifunk-rhein-neckar.de/data/nodes.json") …
n1ghty
  • 19
  • 9
1 2 3
9
10