aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Giessen <charles@lunarg.com>2025-06-20 17:17:42 -0500
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>2025-06-30 11:21:10 -0500
commitf0f308ad2cdc2e8fd58985d6230df4a29cc44eb6 (patch)
tree45d0c204d2a4d158a0da70db50ccddba789fbca6
parent68441fe74bdc2b0722a630e5b357546728696a0f (diff)
downloadusermoji-f0f308ad2cdc2e8fd58985d6230df4a29cc44eb6.tar.xz
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.
-rw-r--r--vulkaninfo/outputprinter.h24
1 files 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<size_t>(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<size_t>(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<size_t>(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<size_t>(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<size_t>(get_top().indents), '\t') << "\"" << key << "\": ";
+ out << std::string(static_cast<size_t>(get_top().indents), '\t');
+ if (!get_top().is_array) {
+ out << "\"" << key << "\": ";
+ }
if (!value_description.empty()) {
out << "\"" << value << " (" << value_description << ")\"";
value_description = {};