Skip to content

Commit

Permalink
Fix JSON parse error when external_metadata_ is empty (Zarr V3 only).
Browse files Browse the repository at this point in the history
  • Loading branch information
aliddell committed Nov 17, 2023
1 parent 56f0bf8 commit 6eb136a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/zarr.v3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
7 changes: 3 additions & 4 deletions tests/write-zarr-v3-raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 6eb136a

Please sign in to comment.