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

Rendering arrays leave a trailing comma #587

Closed
aromeronavia opened this issue Jun 13, 2023 · 0 comments
Closed

Rendering arrays leave a trailing comma #587

aromeronavia opened this issue Jun 13, 2023 · 0 comments

Comments

@aromeronavia
Copy link
Contributor

aromeronavia commented Jun 13, 2023

Problem

When rendering an array, it renders always a trailing comma, which I'm assuming is not the intended functionality, but instead it should be rendering a comma just for all the elements prior to the last

impl JsonRender for Json {
fn render(&self) -> String {
match *self {
Json::String(ref s) => s.to_string(),
Json::Bool(i) => i.to_string(),
Json::Number(ref n) => n.to_string(),
Json::Null => "".to_owned(),
Json::Array(ref a) => {
let mut buf = String::new();
buf.push('[');
for i in a.iter() {
buf.push_str(i.render().as_ref());
buf.push_str(", ");
}
buf.push(']');
buf
}
Json::Object(_) => "[object]".to_owned(),
}
}
}

Example

We want to render the following array: [1, 2, 3]

Expected Result

It gets rendered as [1, 2, 3]

Actual Result

It gets rendered as [1, 2, 3, ]

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

No branches or pull requests

1 participant