chapel
chapel copied to clipboard
[Feature Request]: Built in JSON value
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.
This would also be helpful for reading Zarr metadata
@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?
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.
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.