From f0f308ad2cdc2e8fd58985d6230df4a29cc44eb6 Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Fri, 20 Jun 2025 17:17:42 -0500 Subject: vulkaninfo: Don't write keys while inside of an array Adds logic to ignore the key when printing a key-value if the current context is an array, since that is not valid JSON. --- vulkaninfo/outputprinter.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/vulkaninfo/outputprinter.h b/vulkaninfo/outputprinter.h index d515b62d..8255e928 100644 --- a/vulkaninfo/outputprinter.h +++ b/vulkaninfo/outputprinter.h @@ -352,7 +352,7 @@ class Printer { } out << std::string(static_cast(get_top().indents), '\t'); // Objects with no name are elements in an array of objects - if (object_name == "" || get_top().element_index != -1) { + if (get_top().is_array || object_name == "" || get_top().element_index != -1) { out << "{\n"; get_top().element_index = -1; } else { @@ -370,12 +370,13 @@ class Printer { } out << std::string(static_cast(get_top().indents), '\t'); - if (get_top().element_index != -1) { - out << "\"" << object_name << "[" << get_top().element_index << "]\": {\n"; + if (get_top().is_array && get_top().element_index != -1) { + out << "\"" << object_name << "[" << get_top().element_index << "]\": "; get_top().element_index = -1; - } else { - out << "\"" << object_name << "\": {\n"; + } else if (!get_top().is_array) { + out << "\"" << object_name << "\": "; } + out << "{\n"; if (!value_description.empty()) { value_description = {}; } @@ -438,9 +439,11 @@ class Printer { } else { get_top().is_first_item = false; } - out << std::string(static_cast(get_top().indents), '\t') << "\"" << array_name << "\": " << "[\n"; - assert(get_top().is_array == false && - "Cant start an array object inside another array, must be enclosed in an object"); + out << std::string(static_cast(get_top().indents), '\t'); + if (!get_top().is_array) { + out << "\"" << array_name << "\": "; + } + out << "[\n"; break; default: break; @@ -513,7 +516,10 @@ class Printer { } else { get_top().is_first_item = false; } - out << std::string(static_cast(get_top().indents), '\t') << "\"" << key << "\": "; + out << std::string(static_cast(get_top().indents), '\t'); + if (!get_top().is_array) { + out << "\"" << key << "\": "; + } if (!value_description.empty()) { out << "\"" << value << " (" << value_description << ")\""; value_description = {}; -- cgit v1.2.3