(stdout string, inputMode string)
| 65 | } |
| 66 | |
| 67 | func parseJqInput(stdout string, inputMode string) (any, error) { |
| 68 | mode := strings.ToLower(strings.TrimSpace(inputMode)) |
| 69 | if mode != "json" && mode != "jsonl" { |
| 70 | mode = "json" |
| 71 | } |
| 72 | |
| 73 | decoder := json.NewDecoder(strings.NewReader(stdout)) |
| 74 | decoder.UseNumber() |
| 75 | if mode == "jsonl" { |
| 76 | var values []any |
| 77 | for { |
| 78 | var value any |
| 79 | err := decoder.Decode(&value) |
| 80 | if errors.Is(err, io.EOF) { |
| 81 | break |
| 82 | } |
| 83 | if err != nil { |
| 84 | return nil, err |
| 85 | } |
| 86 | values = append(values, value) |
| 87 | } |
| 88 | return values, nil |
| 89 | } |
| 90 | |
| 91 | var value any |
| 92 | if err := decoder.Decode(&value); err != nil { |
| 93 | return nil, err |
| 94 | } |
| 95 | if err := decoder.Decode(&struct{}{}); !errors.Is(err, io.EOF) { |
| 96 | if err == nil { |
| 97 | return nil, errors.New("expected a single JSON value") |
| 98 | } |
| 99 | return nil, err |
| 100 | } |
| 101 | |
| 102 | return value, nil |
| 103 | } |
| 104 | |
| 105 | func executeJqQuery(queryText string, input any) ([]any, error) { |
| 106 | query, err := gojq.Parse(queryText) |
no outgoing calls