From 074296c47886ba0801ec08d48d78b2fc13f817ad Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Tue, 25 Mar 2025 10:38:12 +0100 Subject: [PATCH] Fix up parser --- processor/jsonpath/jsonpath.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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]) }