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

Function LocateJSONPathInYAML

pkg/parser/json_path_locator.go:72–92  ·  view source on GitHub ↗

LocateJSONPathInYAML finds the line/column position of a JSON path in YAML source

(yamlContent string, jsonPath string)

Source from the content-addressed store, hash-verified

70
71// LocateJSONPathInYAML finds the line/column position of a JSON path in YAML source
72func LocateJSONPathInYAML(yamlContent string, jsonPath string) JSONPathLocation {
73 jsonPathLog.Printf("Locating JSON path in YAML: %s", jsonPath)
74
75 if jsonPath == "" {
76 // Root level error - return start of content
77 return JSONPathLocation{Line: 1, Column: 1, Found: true}
78 }
79
80 // Parse the path segments
81 pathSegments := parseJSONPath(jsonPath)
82 if len(pathSegments) == 0 {
83 return JSONPathLocation{Line: 1, Column: 1, Found: true}
84 }
85
86 jsonPathLog.Printf("Parsed %d path segments", len(pathSegments))
87
88 // Use a more sophisticated line-by-line approach to find the path
89 location := findPathInYAMLLines(yamlContent, pathSegments)
90 jsonPathLog.Printf("Location result: line=%d, column=%d, found=%v", location.Line, location.Column, location.Found)
91 return location
92}
93
94// LocateJSONPathForPathInfo finds the line/column position in YAML source for a JSONPathInfo.
95// It uses ErrorKind for structural property-name extraction when available, and falls back to

Calls 3

parseJSONPathFunction · 0.85
findPathInYAMLLinesFunction · 0.85
PrintfMethod · 0.45