[LTP] [PATCH 1/2] metadata: data_storage: Fix hash to json object serialization
Cyril Hrubis
chrubis@suse.cz
Fri Jun 20 17:43:45 CEST 2025
We have to move the curly braces into the switch() that prints the JSON
values otherwise inner object will not have curly braces around them and
the resulting JSON is not valid.
The changes between the old generated metadata and new metadata are only
in the whitespaces:
diff -w ltp-prev.json ltp.json
7c7
< "version": "20250530-41-g080ced081"
---
> "version": "20250530-42-g73a97b583"
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
metadata/data_storage.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/metadata/data_storage.h b/metadata/data_storage.h
index 82d67b829..f837feec8 100644
--- a/metadata/data_storage.h
+++ b/metadata/data_storage.h
@@ -396,14 +396,16 @@ static inline void data_to_json_(struct data_node *self, FILE *f, unsigned int p
data_fprintf(f, padd, "null");
break;
case DATA_HASH:
+ data_fprintf(f, do_padd ? padd : 0, "{\n");
for (i = 0; i < self->hash.elems_used; i++) {
- data_fprintf(f, padd, "\"%s\": ", self->hash.elems[i].id);
+ data_fprintf(f, padd+1, "\"%s\": ", self->hash.elems[i].id);
data_to_json_(self->hash.elems[i].node, f, padd+1, 0);
if (i < self->hash.elems_used - 1)
fprintf(f, ",\n");
else
fprintf(f, "\n");
}
+ data_fprintf(f, padd, "}");
break;
case DATA_ARRAY:
data_fprintf(f, do_padd ? padd : 0, "[\n");
@@ -421,9 +423,7 @@ static inline void data_to_json_(struct data_node *self, FILE *f, unsigned int p
static inline void data_to_json(struct data_node *self, FILE *f, unsigned int padd)
{
- fprintf(f, "{\n");
- data_to_json_(self, f, padd + 1, 1);
- data_fprintf(f, padd, "}");
+ data_to_json_(self, f, padd, 0);
}
#endif /* DATA_STORAGE_H__ */
--
2.49.0
More information about the ltp
mailing list