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

Function extractYAMLValueAtPath

pkg/parser/schema_suggestions.go:477–490  ·  view source on GitHub ↗

extractYAMLValueAtPath extracts the scalar value at a JSON path from raw YAML frontmatter. Supports top-level paths ("/field") and two-level nested paths ("/parent/child"). Deeper paths return an empty string.

(yamlContent, jsonPath string)

Source from the content-addressed store, hash-verified

475// Supports top-level paths ("/field") and two-level nested paths ("/parent/child").
476// Deeper paths return an empty string.
477func extractYAMLValueAtPath(yamlContent, jsonPath string) string {
478 if yamlContent == "" || jsonPath == "" {
479 return ""
480 }
481 segments := strings.SplitN(strings.TrimPrefix(jsonPath, "/"), "/", 3)
482 switch len(segments) {
483 case 1:
484 return extractTopLevelYAMLValue(yamlContent, segments[0])
485 case 2:
486 return extractNestedYAMLValue(yamlContent, segments[0], segments[1])
487 default:
488 return ""
489 }
490}
491
492// extractTopLevelYAMLValue extracts the scalar value of a top-level key from raw YAML.
493// Uses horizontal-only whitespace between the colon and value to avoid matching multi-line blocks.

Callers 2

enumSuggestionFunction · 0.85

Calls 2

extractTopLevelYAMLValueFunction · 0.85
extractNestedYAMLValueFunction · 0.85

Tested by 1