logoalt Hacker News

CamouflagedKiwi • yesterday at 6:48 PM • 3 replies • view on HN

I generally like `encoding/json/v2` and I'm glad they did it.

I wish they'd left `MarshalIndent` in there though. The equivalent code is super complicated and non-obvious, so it's a pain to migrate, and it's a pain when you're banging out some quick code and want to dump some readable JSON. I suppose these days the LLMs can write the complicated version for us, of course.


Replies

athorax • yesterday at 6:59 PM

I'm not sure if I'm missing something, but isn't this functionality just moved into jsontext? https://pkg.go.dev/encoding/json/jsontext#Value.Indent

  v := jsontext.Value(b)
  v.Indent()
  fmt.Println(string(v))
➕ show 1 reply
arccy • yesterday at 7:23 PM

    json.Marshal(v, jsontext.WithIndent("  "))

?
lifeisloving • yesterday at 6:55 PM

[flagged]