[DEPRECATED] Go implementation of plcbundle

pretty print json in op cmd

+14 -4
+14 -4
cmd/plcbundle/commands/op.go
··· 314 314 fmt.Printf("\n") 315 315 } 316 316 317 - // Verbose: show full JSON 317 + // Verbose: show full JSON (pretty-printed) 318 318 if verbose { 319 319 fmt.Printf("Raw JSON\n") 320 320 fmt.Printf("────────\n") 321 + 322 + var data []byte 321 323 if len(op.RawJSON) > 0 { 322 - fmt.Println(string(op.RawJSON)) 324 + // Parse and re-format the raw JSON 325 + var temp interface{} 326 + if err := json.Unmarshal(op.RawJSON, &temp); err == nil { 327 + data, _ = json.MarshalIndent(temp, "", " ") 328 + } else { 329 + // Fallback to raw if parse fails 330 + data = op.RawJSON 331 + } 323 332 } else { 324 - data, _ := json.MarshalIndent(op, "", " ") 325 - fmt.Println(string(data)) 333 + data, _ = json.MarshalIndent(op, "", " ") 326 334 } 335 + 336 + fmt.Println(string(data)) 327 337 fmt.Printf("\n") 328 338 } 329 339