chapel icon indicating copy to clipboard operation
chapel copied to clipboard

[Feature Request]: Built in JSON value

Open Iainmon opened this issue 1 year ago • 4 comments

Summary of Feature

Description: Twice I have needed an untyped JSON value for the output of JSON parsing. Serializers and deserializers are great, but if your JSON structure is irregular and conditional, then it is near impossible to write a decent Chapel record/class to load into. Having a basic recursive JSON type would make it easier to conditionally query the JSON structure.

Is this issue currently blocking your progress?

Yes, but I have found a weird solution.

Iainmon avatar Aug 01 '24 14:08 Iainmon

This would also be helpful for reading Zarr metadata

brandon-neth avatar Aug 01 '24 18:08 brandon-neth

@Iainmon : Is what you're requesting here equivalent to wanting:

var x = returnValueOfArbitraryType();

where the return type of the routine couldn't be known at compile-time? Or is it somehow more constrained than that?

bradcray avatar Aug 12 '24 22:08 bradcray

I think what Iain means here is a "JSON object type":

var json: owned Json = readJson();
if var arr = json.borrow() : JsonArray {
   // It's a JSON array!
   // do stuff
} else if var obj = json.borrow() : JsonObject {
  // It's a JSON dictionary!
  // do stuff
} else {
 // ...
}

This way you have a runtime way to examine the contents.

DanilaFe avatar Aug 12 '24 22:08 DanilaFe

Yes, this is it. There could be a different interface for scrutinizing what kind of json value it represents, but the idea is the same.

Iainmon avatar Aug 12 '24 22:08 Iainmon