Skip to content

Allow traversal of all keywords, not only those implementing JSONPather #106

@dan-j

Description

@dan-j

What feature or capability would you like?

Implement https://github.com/qri-io/jsonpointer WalkJSON() api by adding JSONProps() map[string]interface{} methods to all relevant keywords.

At the moment there is no API to traverse parsed schemas down to keywords with scalar values, because scalar keywords do not implement JSONPather. This makes sense, because a keyword like Description shouldn't have a JSONProp(name string) interface{} method.

Do you have a proposed solution?

Adding a new method JSONProps() map[string]interface{} which returns all keywords would support this use-case, whilst JSONChildren() can maintain it's current functionality and only return keywords which are JSONPathers.

Have you considered any alternative solutions or workarounds?

Implement an exported function WalkJSON() which works similarly to https://github.com/qri-io/jsonpointer, and uses the s.keywords slice internally so that all children are traversed. However, for my specific use-case, I have a problem with the current implementation of WalkJSON() because I also need to know the path being traversed, i.e. when visit is called, I need to know which element in the JSON I'm visiting, i.e. /properties/myProperty/type.

Please link any related issues.

I initially created the following issue to add support for using their WalkJSON() function. However, if you look at my second comment, it's not really appropriate: qri-io/jsonpointer#10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions