MCPcopy Create free account
hub / github.com/github/gh-aw / parseJSONPath

Function parseJSONPath

pkg/parser/json_path_locator.go:207–231  ·  view source on GitHub ↗

parseJSONPath parses a JSON path string into segments

(path string)

Source from the content-addressed store, hash-verified

205
206// parseJSONPath parses a JSON path string into segments
207func parseJSONPath(path string) []PathSegment {
208 if path == "" || path == "/" {
209 return []PathSegment{}
210 }
211
212 // Remove leading slash and split by slash
213 path = strings.TrimPrefix(path, "/")
214 parts := strings.Split(path, "/")
215
216 var segments []PathSegment
217 for _, part := range parts {
218 if part == "" {
219 continue
220 }
221
222 // Check if this is an array index
223 if index, err := strconv.Atoi(part); err == nil {
224 segments = append(segments, PathSegment{Type: "index", Value: part, Index: index})
225 } else {
226 segments = append(segments, PathSegment{Type: "key", Value: part})
227 }
228 }
229
230 return segments
231}
232
233// PathSegment represents a segment in a JSON path
234type PathSegment struct {

Callers 4

LocateJSONPathInYAMLFunction · 0.85
navigateToSchemaPathFunction · 0.85
TestParseJSONPathFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseJSONPathFunction · 0.68