Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I need a little help #968

Closed
cyberpunkbln opened this issue Dec 23, 2022 · 2 comments
Closed

I need a little help #968

cyberpunkbln opened this issue Dec 23, 2022 · 2 comments

Comments

@cyberpunkbln
Copy link

Hello,
i want to make an json like this:

[
	{
		"name": "name_01",
		"value": "funkyname",
	},
	{
		"name": "name_02",
		"value": "notsofunkyname",
	}
]

and my database iterate the sql-query and put per iterate the name and the value
name = name_01
value = funkyname

and the json must like
json[0][name]
json[0][value]
json[1][name]
json[1][value]

and so on

give it an easy way. build an mutable array or so?

thx

@kangalio
Copy link

Here you go:

#[derive(serde::Serialize)]
struct Item {
  name: String,
  value: String,
}

let data = vec![
  Item { name: "name_01".into(), value: "funkyname".into() },
  Item { name: "name_02".into(), value: "notsofunkyname".into() },
];
println!("{}", serde_json::to_string(&data).unwrap());

@cyberpunkbln
Copy link
Author

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants