enarx / ciborium

CBOR utilities
Other
222 stars 54 forks source link

[Feature]: Implement convenience accessors for `Value` like `serde_json` #82

Open nakedible-p opened 1 year ago

nakedible-p commented 1 year ago

Is there an existing issue for this?

Description

The Value type in serde_json has convenience accessors of Index trait and .get().

Basically how they work is that .get() will try to index the value with the given type, returning an Option<&Value> as result. Using Index trait however never fails but just returns objects that are "undefined" in JSON terms. What this means in practice is that I can do something like this:

val["networks"][0]["ip_addresses"][0].as_string()

This makes it really convenient to access free form deeply nested JSON data which would be inconvenient to map to nested structures.

In order to implement this, however, the Map variant of Value should probably be changed to something which supports fast random access, as suggested in #81.

Acceptance Criteria

No response

Suggestions for a technical implementation

No response