Skip to content

Rendering arrays leave a trailing comma #587

@aromeronavia

Description

@aromeronavia

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, ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions