mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:07:46 +00:00
jp: Remove trailing comma at end of object/array to make output valid JSON
It's ironic that `jp` currently refuses to parse its own output :^)
This commit is contained in:
parent
c07176bd53
commit
b04e0a7677
1 changed files with 14 additions and 4 deletions
|
@ -82,26 +82,36 @@ int main(int argc, char** argv)
|
||||||
void print(const JsonValue& value, int indent, bool use_color)
|
void print(const JsonValue& value, int indent, bool use_color)
|
||||||
{
|
{
|
||||||
if (value.is_object()) {
|
if (value.is_object()) {
|
||||||
|
size_t printed_members = 0;
|
||||||
|
auto object = value.as_object();
|
||||||
outln("{{");
|
outln("{{");
|
||||||
value.as_object().for_each_member([&](auto& member_name, auto& member_value) {
|
object.for_each_member([&](auto& member_name, auto& member_value) {
|
||||||
|
++printed_members;
|
||||||
print_indent(indent + 1);
|
print_indent(indent + 1);
|
||||||
if (use_color)
|
if (use_color)
|
||||||
out("\"\033[33;1m{}\033[0m\": ", member_name);
|
out("\"\033[33;1m{}\033[0m\": ", member_name);
|
||||||
else
|
else
|
||||||
out("\"{}\": ", member_name);
|
out("\"{}\": ", member_name);
|
||||||
print(member_value, indent + 1, use_color);
|
print(member_value, indent + 1, use_color);
|
||||||
outln(",");
|
if (printed_members < static_cast<size_t>(object.size()))
|
||||||
|
out(",");
|
||||||
|
outln();
|
||||||
});
|
});
|
||||||
print_indent(indent);
|
print_indent(indent);
|
||||||
out("}}");
|
out("}}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (value.is_array()) {
|
if (value.is_array()) {
|
||||||
|
size_t printed_entries = 0;
|
||||||
|
auto array = value.as_array();
|
||||||
outln("[");
|
outln("[");
|
||||||
value.as_array().for_each([&](auto& entry_value) {
|
array.for_each([&](auto& entry_value) {
|
||||||
|
++printed_entries;
|
||||||
print_indent(indent + 1);
|
print_indent(indent + 1);
|
||||||
print(entry_value, indent + 1, use_color);
|
print(entry_value, indent + 1, use_color);
|
||||||
outln(",");
|
if (printed_entries < static_cast<size_t>(array.size()))
|
||||||
|
out(",");
|
||||||
|
outln();
|
||||||
});
|
});
|
||||||
print_indent(indent);
|
print_indent(indent);
|
||||||
out("]");
|
out("]");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue