From 6eb136aff2192a30d062b0e674f6b09997f836b0 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Fri, 17 Nov 2023 16:28:52 -0500 Subject: [PATCH] Fix JSON parse error when external_metadata_ is empty (Zarr V3 only). --- src/zarr.v3.cpp | 4 +++- tests/write-zarr-v3-raw.cpp | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/zarr.v3.cpp b/src/zarr.v3.cpp index d3c060e5..7237147d 100644 --- a/src/zarr.v3.cpp +++ b/src/zarr.v3.cpp @@ -302,7 +302,9 @@ zarr::ZarrV3::write_group_metadata_() const using json = nlohmann::json; json metadata; - metadata["attributes"]["acquire"] = json::parse(external_metadata_json_); + metadata["attributes"]["acquire"] = + external_metadata_json_.empty() ? "" + : json::parse(external_metadata_json_); auto path = (dataset_root_ / "meta" / "root.group.json").string(); common::write_string(path, metadata.dump(4)); diff --git a/tests/write-zarr-v3-raw.cpp b/tests/write-zarr-v3-raw.cpp index b70637a7..047bca80 100644 --- a/tests/write-zarr-v3-raw.cpp +++ b/tests/write-zarr-v3-raw.cpp @@ -98,15 +98,14 @@ setup(AcquireRuntime* runtime) SIZED("ZarrV3"), &props.video[0].storage.identifier)); - const char external_metadata[] = R"({"hello":"world"})"; const struct PixelScale sample_spacing_um = { 1, 1 }; storage_properties_init(&props.video[0].storage.settings, 0, (char*)filename, strlen(filename) + 1, - (char*)external_metadata, - sizeof(external_metadata), + nullptr, + 0, sample_spacing_um); storage_properties_set_chunking_props(&props.video[0].storage.settings, @@ -217,7 +216,7 @@ validate(AcquireRuntime* runtime) f = std::ifstream(metadata_path); metadata = json::parse(f); - CHECK("world" == metadata["attributes"]["acquire"]["hello"]); + CHECK("" == metadata["attributes"]["acquire"]); // check the array metadata file metadata_path = test_path / "meta" / "root" / "0.array.json";