Skip to content

Commit

Permalink
Add helper for loading JSON.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 720582086
  • Loading branch information
jan-matthis authored and copybara-github committed Jan 28, 2025
1 parent 5d65ceb commit 016bd64
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions connectomics/common/ts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
# limitations under the License.
"""TensorStore utilities."""

import json
from typing import Any, Mapping

import tensorstore as ts


Expand All @@ -30,3 +32,16 @@ def write_json(to_write: Mapping[str, Any],
kvstore=kvstore,
), context=context).result().write(to_write).result()
return to_write


def load_json(kvstore: ts.KvStore.Spec,
context: ts.Context = None) -> Mapping[str, Any]:
"""Load JSON data using TensorStore driver."""
if context is None:
context = ts.Context()
ds = ts.open(
dict(
driver='json',
kvstore=kvstore,
), context=context).result()
return json.loads(str(ds.read().result()))

0 comments on commit 016bd64

Please sign in to comment.