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

Function formatJSONValue

pkg/cli/printer.go:327–360  ·  view source on GitHub ↗
(key string, value any)

Source from the content-addressed store, hash-verified

325}
326
327func formatJSONValue(key string, value any) string {
328 switch v := value.(type) {
329 case string:
330 // Handle multiline strings by displaying with actual newlines
331 if strings.Contains(v, "\n") {
332 // Format as: key: "content with
333 // actual line breaks"
334 return fmt.Sprintf("%s: %q", bold(key), v)
335 }
336 // Regular string with proper escaping
337 return fmt.Sprintf("%s: %q", bold(key), v)
338
339 case []any:
340 if len(v) == 0 {
341 return bold(key) + ": []"
342 }
343 // Single item arrays are rendered on a single line
344 if len(v) == 1 {
345 jsonBytes, _ := json.Marshal(v)
346 return fmt.Sprintf("%s: %s", bold(key), string(jsonBytes))
347 }
348 // Show full array contents
349 jsonBytes, _ := json.MarshalIndent(v, "", " ")
350 return fmt.Sprintf("%s: %s", bold(key), string(jsonBytes))
351
352 case map[string]any:
353 jsonBytes, _ := json.MarshalIndent(v, "", " ")
354 return fmt.Sprintf("%s: %s", bold(key), string(jsonBytes))
355
356 default:
357 jsonBytes, _ := json.Marshal(v)
358 return fmt.Sprintf("%s: %s", bold(key), string(jsonBytes))
359 }
360}

Callers 2

formatToolCallArgumentsFunction · 0.85
formatParsedJSONFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected