MCPcopy Index your code
hub / github.com/docker/docker-agent / formatParsedJSON

Function formatParsedJSON

pkg/cli/printer.go:296–325  ·  view source on GitHub ↗
(data any)

Source from the content-addressed store, hash-verified

294}
295
296func formatParsedJSON(data any) string {
297 switch v := data.(type) {
298 case map[string]any:
299 if len(v) == 0 {
300 return "()"
301 }
302
303 parts := make([]string, 0, len(v))
304 hasMultilineContent := false
305
306 for key, value := range v {
307 formatted := formatJSONValue(key, value)
308 parts = append(parts, formatted)
309 if strings.Contains(formatted, "\n") {
310 hasMultilineContent = true
311 }
312 }
313
314 if len(parts) == 1 && !hasMultilineContent {
315 return fmt.Sprintf("(%s)", parts[0])
316 }
317
318 return fmt.Sprintf("(\n %s\n)", strings.Join(parts, "\n "))
319
320 default:
321 // For non-object types, use standard JSON formatting
322 formatted, _ := json.MarshalIndent(data, "", " ")
323 return fmt.Sprintf("(%s)", string(formatted))
324 }
325}
326
327func formatJSONValue(key string, value any) string {
328 switch v := value.(type) {

Callers 1

formatToolCallResponseFunction · 0.85

Calls 1

formatJSONValueFunction · 0.85

Tested by

no test coverage detected