diff --git a/processor/jsonpath/jsonpath.go b/processor/jsonpath/jsonpath.go index 3ac082c..97cb6fa 100644 --- a/processor/jsonpath/jsonpath.go +++ b/processor/jsonpath/jsonpath.go @@ -1,4 +1,4 @@ -package main +package jsonpath import ( "fmt" @@ -27,12 +27,14 @@ func ParseJSONPath(path string) ([]JSONStep, error) { return nil, fmt.Errorf("path must start with $") } - path = path[1:] steps := []JSONStep{} i := 0 for i < len(path) { switch path[i] { + case '$': + steps = append(steps, JSONStep{Type: RootStep}) + i++ case '.': i++ if i < len(path) && path[i] == '.' { @@ -51,7 +53,6 @@ func ParseJSONPath(path string) ([]JSONStep, error) { } i = nextPos } - case '[': // Index step i++ @@ -66,7 +67,6 @@ func ParseJSONPath(path string) ([]JSONStep, error) { steps = append(steps, JSONStep{Type: IndexStep, Index: index}) } i = nextPos + 1 // Skip closing ] - default: return nil, fmt.Errorf("unexpected character: %c", path[i]) }