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

Problems working with rust and postgres data types

I'm triying to do an Api REST with rust and postres but I cant make it work because the relation between these two. The actual problem is that I have a column in postgres as jsonb and when I return the data and try to save it in a struct always…
A G
  • 3
  • 2
0
votes
2 answers

How to construct a serde struct with this type of JSON format?

I'm trying to construct a JSON in rust using serde using structs. { "parent": { "database_id": "123" }, "properties": { "title": { "title": [ { "text": { "content": "Yurts in Big Sur, 123" …
Xin Li
  • 1
  • 3
0
votes
1 answer

Why does serde::json need to copy this ref?

Here's some simple code that seems like it should work: use serde_json; use std::io::Write; fn test(writer: &mut dyn Write) { serde_json::to_writer(writer, "test1").unwrap(); serde_json::to_writer(writer, "test2").unwrap(); } But it…
D0SBoots
  • 705
  • 6
  • 18
0
votes
1 answer

Panic while deserializing JSON data

I'm currently trying to use some API keys to access the Kucoin exchange from my program.I want to be able to have a global initialization of the keys so I can reuse them as credentials in different functions and modules. I store the keys in a…
Kirima
  • 25
  • 6
0
votes
1 answer

How to parse a sequence of anonymous enum values into a tuple struct?

Is it possible to parse a JSON array into a tuple struct with a vector of enums? use serde::Deserialize; #[derive(Deserialize, Debug, PartialEq, Eq)] enum Data { Single(i32), List(Vec), } #[derive(Deserialize, Debug, PartialEq,…
Paweł Rubin
  • 2,030
  • 1
  • 14
  • 25
0
votes
1 answer

Serde Json visitor to derserialise into generic struct

I have a nested JSON structure, the relevant bits of which look like this: { "params": { "foo": { "type": "integer" }, "bar": { "type": "integer", "choices": [ 0, 26, 4 ] }, …
Alex
  • 2,270
  • 3
  • 33
  • 65
0
votes
1 answer

Use simd-json with reqwest

How can one get the Rust reqwest library to parse json via simd-json? I believe the current default is serde_json. reqwest::get("https://www.example.com").await.json().await If it is impossible, how does one make a web request and parse with…
Test
  • 962
  • 9
  • 26
0
votes
1 answer

Remove duplicates from array of serde_json::Value in Rust

I have an array of generic serde_json::Value, that may also contain duplicates. serde_json::Value does not implement std::cmp::Ord and I also cannot implement the trait because only traits defined in the current crate can be implemented for…
0
votes
1 answer

Deserialize f64 using serde and divide by 100

Id like to divide my_val by 100 on deserialization: #[derive(Debug, Deserialize, Clone)] pub struct MyObject { pub other: String, pub my_val: f64, // <-- divide by 100.0 } I found deserialize_with but the only examples I could find is…
PascalVKooten
  • 20,643
  • 17
  • 103
  • 160
0
votes
1 answer

Getting "trailing characters" error when trying to parse string with serde_json

I need to convert a specific string in serde_json::Value, but getting a trailing character error while using: let new_str = "73723235c81ebbec0" let json_value: serde_json::Value = serde_json::from_str(new_str).unwrap(); Error: trailing characters…
Pawan Bisht
  • 215
  • 2
  • 9
0
votes
1 answer

How to implement Iterator in Rust for third party library

Im trying to make the following work use serde_json::Value; #[tokio::main] async fn main() -> Result<(), Box> { let json = reqwest::get("https://www.bitmex.com/api/v1/instrument/indices") .await? …
blanNL
  • 360
  • 1
  • 11
0
votes
1 answer

How to sort JSON in rust?

Is it possible to sort JSON in rust language? If it is possible then how? Like this one: const headers = { 'checkout-account': '1234', 'checkout-algorithm': 'sha256', 'checkout-method': 'POST', 'checkout-nonce': '564635208570151', …
chifmaster113
  • 13
  • 1
  • 1
0
votes
2 answers

How to correctly parse JSON with Unicode escape sequences?

playground use serde_json::json; // 1.0.66 use std::str; fn main() { let input = "{\"a\": \"b\\u001fc\"}"; let bytes = input.as_bytes(); let json: serde_json::Value = serde_json::from_slice(bytes).unwrap(); for (_k, v) in…
0
votes
1 answer

Rust: how to derive Deserialize for struct with generic types?

#[derive(Deserialize)] struct S<'d, T> where T: Deserialize<'d> { foo: T, other_field: String } The above code fails to compile, complaining unused lifetime parameter, but if I remove it, Deserialize would missing lifetime. Can the above code…
Incömplete
  • 853
  • 8
  • 20
0
votes
1 answer

Can't write field to MongoDB document if using skip_serialize serde attribute in Rust

I want to be able to write a field into a mongo document, but avoid serializing it when passing the object as a response to the client. I tried using #[serde(skip_serializing)]. However, it doesn't work as I intended, which I think is because when…