{"id":465238,"date":"2025-06-30T15:01:28","date_gmt":"2025-06-30T15:01:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=465238"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=465238","title":{"rendered":"<span>\u042d\u0432\u043e\u043b\u044e\u0446\u0438\u044f JSON \u0432 Go: \u043e\u0442 v1 \u043a v2<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u0430 <a href=\"https:\/\/pkg.go.dev\/encoding\/json\/v2\" rel=\"noopener noreferrer nofollow\"><code>json\/v2<\/code><\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 Go 1.25 (\u0430\u0432\u0433\u0443\u0441\u0442 2025) \u2014 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u0412 v2 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 API \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u043b\u0443\u0447\u0448\u0438\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c!<\/p>\n<p>\u0411\u0430\u0437\u043e\u0432\u043e\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>Marshal<\/code> \u0438 <code>Unmarshal<\/code> \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0432 v1, \u0442\u0430\u043a \u0438 \u0432 v2:<\/p>\n<pre><code class=\"go\">type Person struct {     Name string     Age  int } <\/code><\/pre>\n<pre><code class=\"go\">alice := Person{Name: \"Alice\", Age: 25}  \/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0410\u043b\u0438\u0441\u0443. b, err := json.Marshal(alice) fmt.Println(string(b), err)  \/\/ \u0414\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0410\u043b\u0438\u0441\u0443. err = json.Unmarshal(b, &amp;alice) fmt.Println(alice, err) <\/code><\/pre>\n<pre><code>{\"Name\":\"Alice\",\"Age\":25} &lt;nil&gt; {Alice 25} &lt;nil&gt; <\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u043f\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043e\u0442\u043b\u0438\u0447\u0438\u044f\u043c v2 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 v1.<\/p>\n<h3>MarshalWrite \u0438 UnmarshalRead<\/h3>\n<p>\u0412 v1 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 <code>Encoder<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u0438\u0441\u0430\u0442\u044c \u0432 <code>io.Writer<\/code>, \u0438 <code>Decoder<\/code> \u2014 \u0447\u0442\u043e\u0431\u044b \u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0437 <code>io.Reader<\/code>:<\/p>\n<pre><code class=\"go\">\/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0410\u043b\u0438\u0441\u0443. alice := Person{Name: \"Alice\", Age: 25} out := new(strings.Builder) \/\/ io.Writer enc := json.NewEncoder(out) enc.Encode(alice) fmt.Println(out.String())  \/\/ \u0414\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0411\u043e\u0431\u0430. in := strings.NewReader(`{\"Name\":\"Bob\",\"Age\":30}`) \/\/ io.Reader dec := json.NewDecoder(in) var bob Person dec.Decode(&amp;bob) fmt.Println(bob) <\/code><\/pre>\n<pre><code>{\"Name\":\"Alice\",\"Age\":25}  {Bob 30} <\/code><\/pre>\n<blockquote>\n<p>\u042f \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b. \u041d\u0435 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0442\u0430\u043a \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u30c4<\/p>\n<\/blockquote>\n<p>\u0412 v2 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>MarshalWrite<\/code> \u0438 <code>UnmarshalRead<\/code> \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0431\u0435\u0437 \u043f\u043e\u0441\u0440\u0435\u0434\u043d\u0438\u043a\u043e\u0432:<\/p>\n<pre><code class=\"go\">\/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0410\u043b\u0438\u0441\u0443. alice := Person{Name: \"Alice\", Age: 25} out := new(strings.Builder) json.MarshalWrite(out, alice) fmt.Println(out.String())  \/\/ \u0414\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0411\u043e\u0431\u0430. in := strings.NewReader(`{\"Name\":\"Bob\",\"Age\":30}`) var bob Person json.UnmarshalRead(in, &amp;bob) fmt.Println(bob) <\/code><\/pre>\n<pre><code>{\"Name\":\"Alice\",\"Age\":25} {Bob 30 false} <\/code><\/pre>\n<p>\u041d\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435:<\/p>\n<ul>\n<li>\n<p><code>MarshalWrite<\/code> \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0440\u043e\u043a\u0438, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0441\u0442\u0430\u0440\u043e\u0433\u043e <code>Encoder.Encode<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>UnmarshalRead<\/code> \u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0437 \u0440\u0438\u0434\u0435\u0440\u0430 \u0432\u0441\u0435 \u043f\u043e\u0434\u0440\u044f\u0434 \u0434\u043e <code>io.EOF<\/code>, \u0430 \u0441\u0442\u0430\u0440\u044b\u0439 <code>Decoder.Decode<\/code> \u0447\u0438\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 JSON-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<\/ul>\n<h3>MarshalEncode \u0438 UnmarshalDecode<\/h3>\n<p>\u0422\u0438\u043f\u044b <code>Encoder<\/code> \u0438 <code>Decoder<\/code> \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043d\u043e\u0432\u043e\u043c \u043f\u0430\u043a\u0435\u0442\u0435 <a href=\"https:\/\/pkg.go.dev\/encoding\/json\/jsontext\" rel=\"noopener noreferrer nofollow\"><code>jsontext<\/code><\/a>, \u0438 \u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0441\u0438\u043b\u044c\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438\u0441\u044c (\u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f).<\/p>\n<p>\u0418\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 <code>json<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u0447\u043d\u043e \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043f\u0438\u0441\u0430\u0442\u044c JSON, \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043a\u0430\u043a \u0440\u0430\u043d\u044c\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 <code>Encode<\/code> \u0438 <code>Decode<\/code>:<\/p>\n<ul>\n<li>\n<p>v1 <code>Encoder.Encode<\/code> \u2192 v2 <code>json.MarshalEncode<\/code> + <code>jsontext.Encoder<\/code><\/p>\n<\/li>\n<li>\n<p>v1 <code>Decoder.Decode<\/code> \u2192 v2 <code>json.UnmarshalDecode<\/code> + <code>jsontext.Decoder<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a:<\/p>\n<pre><code class=\"go\">people := []Person{     {Name: \"Alice\", Age: 25},     {Name: \"Bob\", Age: 30},     {Name: \"Cindy\", Age: 15}, } out := new(strings.Builder) enc := jsontext.NewEncoder(out)  for _, p := range people {     \/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442 Person \u0437\u0430 \u0432\u044b\u0437\u043e\u0432.     json.MarshalEncode(enc, p) }  fmt.Print(out.String()) <\/code><\/pre>\n<pre><code>{\"Name\":\"Alice\",\"Age\":25} {\"Name\":\"Bob\",\"Age\":30} {\"Name\":\"Cindy\",\"Age\":15} <\/code><\/pre>\n<p>\u041f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u0434\u0435\u043a\u043e\u0434\u0435\u0440:<\/p>\n<pre><code class=\"go\">in := strings.NewReader(`     {\"Name\":\"Alice\",\"Age\":25}     {\"Name\":\"Bob\",\"Age\":30}     {\"Name\":\"Cindy\",\"Age\":15} `) dec := jsontext.NewDecoder(in)  for {     var p Person     \/\/ \u0414\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442 Person \u0437\u0430 \u0432\u044b\u0437\u043e\u0432.     err := json.UnmarshalDecode(dec, &amp;p)     if err == io.EOF {         break     }     fmt.Println(p) } <\/code><\/pre>\n<pre><code>{Alice 25} {Bob 30} {Cindy 15} <\/code><\/pre>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <code>UnmarshalRead<\/code>, \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>UnmarshalDecode<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u2014 \u043e\u043d\u0430 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0437\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0437\u043e\u0432, \u0430 \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u0442 \u0432\u0441\u0435 \u0441\u0440\u0430\u0437\u0443 \u0434\u043e <code>io.EOF<\/code>.<\/p>\n<h3>\u041e\u043f\u0446\u0438\u0438<\/h3>\n<p>\u041e\u043f\u0446\u0438\u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442 \u043d\u044e\u0430\u043d\u0441\u044b \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><code>FormatNilMapAsNull<\/code> \u0438 <code>FormatNilSliceAsNull<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442, \u043a\u0430\u043a \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c nil-\u043a\u0430\u0440\u0442\u044b \u0438 \u0441\u0440\u0435\u0437\u044b.<\/p>\n<\/li>\n<li>\n<p><code>MatchCaseInsensitiveNames<\/code> \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u043c\u0435\u043d\u0430 \u0431\u0435\u0437 \u0443\u0447\u0435\u0442\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>Name<\/code> \u2194 <code>name<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>Multiline<\/code> \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 JSON-\u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a.<\/p>\n<\/li>\n<li>\n<p><code>OmitZeroStructFields<\/code> \u0443\u0431\u0438\u0440\u0430\u0435\u0442 \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u043e\u043b\u044f \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p><code>SpaceAfterColon<\/code> \u0438 <code>SpaceAfterComma<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442 \u043f\u0440\u043e\u0431\u0435\u043b \u043f\u043e\u0441\u043b\u0435 <code>:<\/code> \u0438\u043b\u0438 <code>,<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>StringifyNumbers<\/code> \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0447\u0438\u0441\u043b\u0430 \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><code>WithIndent<\/code> \u0438 <code>WithIndentPrefix<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442 \u043e\u0442\u0441\u0442\u0443\u043f\u044b \u0434\u043b\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 (\u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>MarshalIndent<\/code> \u0432 v2 \u0443\u0434\u0430\u043b\u0435\u043d\u0430).<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0446\u0438\u0439:<\/p>\n<pre><code class=\"go\">alice := Person{Name: \"Alice\", Age: 25} b, _ := json.Marshal(     alice,     json.OmitZeroStructFields(true),     json.StringifyNumbers(true),     jsontext.WithIndent(\"  \"), ) fmt.Println(string(b)) <\/code><\/pre>\n<pre><code>{   \"Name\": \"Alice\",   \"Age\": \"25\" } <\/code><\/pre>\n<p>\u041e\u043f\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>JoinOptions<\/code>:<\/p>\n<pre><code class=\"go\">alice := Person{Name: \"Alice\", Age: 25} opts := json.JoinOptions(     jsontext.SpaceAfterColon(true),     jsontext.SpaceAfterComma(true), ) b, _ := json.Marshal(alice, opts) fmt.Println(string(b)) <\/code><\/pre>\n<pre><code>{\"Name\": \"Alice\", \"Age\": 25} <\/code><\/pre>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u043f\u0446\u0438\u0439 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438: \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 <a href=\"https:\/\/pkg.go.dev\/encoding\/json\/v2#Options\" rel=\"noopener noreferrer nofollow\"><code>json<\/code><\/a>, \u0434\u0440\u0443\u0433\u0438\u0435 \u2014 \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 <a href=\"https:\/\/pkg.go.dev\/encoding\/json\/jsontext#Options\" rel=\"noopener noreferrer nofollow\"><code>jsontext<\/code><\/a>.<\/p>\n<h3>\u0422\u0435\u0433\u0438<\/h3>\n<p>v2 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u0435\u0433\u0438 \u043f\u043e\u043b\u0435\u0439 \u0438\u0437 v1:<\/p>\n<ul>\n<li>\n<p><code>omitzero<\/code> \u0438 <code>omitempty<\/code> \u2014 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><code>string<\/code> \u2014 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><code>-<\/code> \u2014 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e:<\/p>\n<ul>\n<li>\n<p><code>case:ignore<\/code> \u0438 <code>case:strict<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435.<\/p>\n<\/li>\n<li>\n<p><code>format:template<\/code> \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443.<\/p>\n<\/li>\n<li>\n<p><code>inline<\/code> \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u044b\u0432\u043e\u0434 \u00ab\u043f\u043b\u043e\u0441\u043a\u0438\u043c\u00bb, \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044f \u043f\u043e\u043b\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><code>unknown<\/code> \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u0435 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0432 \u043e\u0434\u043d\u043e.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f <code>inline<\/code> \u0438 <code>format<\/code>:<\/p>\n<pre><code class=\"go\">type Person struct {     Name string         `json:\"name\"`     \/\/ \u0424\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u0442\u0443 \u043a\u0430\u043a \u0433\u0433\u0433\u0433-\u043c\u043c-\u0434\u0434.     BirthDate time.Time `json:\"birth_date,format:DateOnly\"`     \/\/ \u0412\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u043e\u043b\u044f \u0430\u0434\u0440\u0435\u0441\u0430 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 Person.     Address             `json:\",inline\"` }  type Address struct {     Street string `json:\"street\"`     City   string `json:\"city\"` }  func main() {     alice := Person{         Name: \"Alice\",         BirthDate: time.Date(2001, 7, 15, 12, 35, 43, 0, time.UTC),         Address: Address{             Street: \"123 Main St\",             City:   \"Wonderland\",         },     }     b, _ := json.Marshal(alice, jsontext.WithIndent(\"  \"))     fmt.Println(string(b)) } <\/code><\/pre>\n<pre><code>{   \"name\": \"Alice\",   \"birth_date\": \"2001-07-15\",   \"street\": \"123 Main St\",   \"city\": \"Wonderland\" } <\/code><\/pre>\n<p>\u0418 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f <code>unknown<\/code>:<\/p>\n<pre><code class=\"go\">type Person struct {     Name string         `json:\"name\"`     \/\/ \u0421\u043e\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043f\u043e\u043b\u044f Person     \/\/ \u0432 \u043f\u043e\u043b\u0435 Data.     Data map[string]any `json:\",unknown\"` }  func main() {     src := `{         \"name\": \"Alice\",         \"hobby\": \"adventure\",         \"friends\": [             {\"name\": \"Bob\"},             {\"name\": \"Cindy\"}         ]     }`     var alice Person     json.Unmarshal([]byte(src), &amp;alice)     fmt.Println(alice) } <\/code><\/pre>\n<pre><code>{Alice map[friends:[map[name:Bob] map[name:Cindy]] hobby:adventure]} <\/code><\/pre>\n<h3>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440\u044b<\/h3>\n<p>\u041a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b <code>Marshaler<\/code> \u0438 <code>Unmarshaler<\/code>. \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0432 v1, \u0442\u0430\u043a \u0438 \u0432 v2:<\/p>\n<pre><code class=\"go\">\/\/ \u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0438\u043f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \/\/ true \u2014 \u044d\u0442\u043e \"\u2713\", \u0430 false \u2014 \"\u2717\". type Success bool  func (s Success) MarshalJSON() ([]byte, error) {     if s {         return []byte(`\"\u2713\"`), nil     }     return []byte(`\"\u2717\"`), nil }  func (s *Success) UnmarshalJSON(data []byte) error {     \/\/ \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u0430 \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438.     *s = string(data) == `\"\u2713\"`     return nil }  func main() {     \/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c true -&gt; \u2713.     val := Success(true)     data, err := json.Marshal(val)     fmt.Println(string(data), err)      \/\/ \u0414\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u2713 -&gt; true.     src := []byte(`\"\u2713\"`)     err = json.Unmarshal(src, &amp;val)     fmt.Println(val, err) } <\/code><\/pre>\n<pre><code>\"\u2713\" &lt;nil&gt; true &lt;nil&gt; <\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0441\u043e\u0432\u0435\u0442\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b <code>MarshalerTo<\/code> \u0438 <code>UnmarshalerFrom<\/code> (\u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435):<\/p>\n<pre><code class=\"go\">\/\/ \u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0438\u043f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \/\/ true \u2014 \u044d\u0442\u043e \"\u2713\", \u0430 false \u2014 \"\u2717\". type Success bool  func (s Success) MarshalJSONTo(enc *jsontext.Encoder) error {     if s {         return enc.WriteToken(jsontext.String(\"\u2713\"))     }     return enc.WriteToken(jsontext.String(\"\u2717\")) }  func (s *Success) UnmarshalJSONFrom(dec *jsontext.Decoder) error {     \/\/ \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u0430 \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438.     tok, err := dec.ReadToken()     *s = tok.String() == `\"\u2713\"`     return err }  func main() {     \/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c true -&gt; \u2713.     val := Success(true)     data, err := json.Marshal(val)     fmt.Println(string(data), err)      \/\/ \u0414\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u2713 -&gt; true.     src := []byte(`\"\u2713\"`)     err = json.Unmarshal(src, &amp;val)     fmt.Println(val, err) } <\/code><\/pre>\n<pre><code>\"\u2713\" &lt;nil&gt; true &lt;nil&gt; <\/code><\/pre>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0432\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u044b \u043e\u0434\u043d\u0438\u043c \u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440\u043e\u043c (\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u043c) \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440\u044b \u0438 \u0430\u043d\u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440\u044b \u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u2014 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>MarshalFunc<\/code> \u0438 <code>UnmarshalFunc<\/code>.<\/p>\n<pre><code class=\"go\">func MarshalFunc[T any](fn func(T) ([]byte, error)) *Marshalers func UnmarshalFunc[T any](fn func([]byte, T) error) *Unmarshalers <\/code><\/pre>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>bool<\/code> \u0432 <code>\u2713<\/code> \u0438\u043b\u0438 <code>\u2717<\/code> \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"go\">\/\/ \u041a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. boolMarshaler := json.MarshalFunc(     func(val bool) ([]byte, error) {         if val {             return []byte(`\"\u2713\"`), nil         }         return []byte(`\"\u2717\"`), nil     }, )  \/\/ \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0432 Marshal \/\/ \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0446\u0438\u0438 WithMarshalers. val := true data, err := json.Marshal(val, json.WithMarshalers(boolMarshaler)) fmt.Println(string(data), err) <\/code><\/pre>\n<pre><code>\"\u2713\" &lt;nil&gt; <\/code><\/pre>\n<p>\u0418 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>\u2713<\/code> \u0438\u043b\u0438 <code>\u2717<\/code> \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 <code>bool<\/code>:<\/p>\n<pre><code class=\"go\">\/\/ \u0414\u0435\u043a\u043e\u0434\u0435\u0440 \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. boolUnmarshaler := json.UnmarshalFunc(     func(data []byte, val *bool) error {         *val = string(data) == `\"\u2713\"`         return nil     }, )  \/\/ \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u0432 \u0432 Unmarshal \/\/ \u0447\u0435\u0440\u0435\u0437 \u043e\u043f\u0446\u0438\u044e WithUnmarshalers. src := []byte(`\"\u2713\"`) var val bool err := json.Unmarshal(src, &amp;val, json.WithUnmarshalers(boolUnmarshaler)) fmt.Println(val, err) <\/code><\/pre>\n<pre><code>true &lt;nil&gt; <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u0432 \u0438 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u043e\u0432 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0442\u0430\u043a\u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>MarshalToFunc<\/code> \u0438 <code>UnmarshalFromFunc<\/code>. \u041e\u043d\u0438 \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 <code>MarshalFunc<\/code> \u0438 <code>UnmarshalFunc<\/code>, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 <code>jsontext.Encoder<\/code> \u0438 <code>jsontext.Decoder<\/code>, \u0430 \u043d\u0435 \u0441 \u0431\u0430\u0439\u0442\u043e\u0432\u044b\u043c\u0438 \u0441\u0440\u0435\u0437\u0430\u043c\u0438.<\/p>\n<pre><code class=\"go\">func MarshalToFunc[T any](fn func(*jsontext.Encoder, T) error) *Marshalers func UnmarshalFromFunc[T any](fn func(*jsontext.Decoder, T) error) *Unmarshalers <\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>JoinMarshalers<\/code> (\u0438 \u0430\u043d\u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>JoinUnmarshalers<\/code>). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (<code>true<\/code>\/<code>false<\/code>) \u0438 \u00ab\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435\u00bb \u0441\u0442\u0440\u043e\u043a\u0438 (<code>on<\/code>\/<code>off<\/code>) \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>\u2713<\/code>\/<code>\u2717<\/code>, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0432 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440 \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"go\">\/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 true\/false \u0432 \u2713\/\u2717. boolMarshaler := json.MarshalToFunc(     func(enc *jsontext.Encoder, val bool) error {         if val {             return enc.WriteToken(jsontext.String(\"\u2713\"))         }         return enc.WriteToken(jsontext.String(\"\u2717\"))     }, ) <\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440 \u0434\u043b\u044f \u00ab\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445\u00bb \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code class=\"go\">\/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u0438\u0434\u0430 on\/off \u0432 \u2713\/\u2717. strMarshaler := json.MarshalToFunc(     func(enc *jsontext.Encoder, val string) error {         if val == \"on\" || val == \"true\" {             return enc.WriteToken(jsontext.String(\"\u2713\"))         }         if val == \"off\" || val == \"false\" {             return enc.WriteToken(jsontext.String(\"\u2717\"))         }         \/\/ SkipFunc \u2014 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0440\u0443\u0435\u0442 Go \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c         \/\/ \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440 \u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435         \/\/ \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440 \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a.         return json.SkipFunc     }, ) <\/code><\/pre>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>JoinMarshalers<\/code> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0438\u0445 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043c\u0430\u0440\u0448\u0430\u043b\u0438\u043d\u0433\u0430 \u0447\u0435\u0440\u0435\u0437 \u043e\u043f\u0446\u0438\u044e <code>WithMarshalers<\/code>:<\/p>\n<pre><code class=\"go\">\/\/ \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e JoinMarshalers. marshalers := json.JoinMarshalers(boolMarshaler, strMarshaler)  \/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0432 JSON \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. vals := []any{true, \"off\", \"hello\"} data, err := json.Marshal(vals, json.WithMarshalers(marshalers)) fmt.Println(string(data), err) <\/code><\/pre>\n<pre><code>[\"\u2713\",\"\u2717\",\"hello\"] &lt;nil&gt; <\/code><\/pre>\n<p>\u0417\u0434\u043e\u0440\u043e\u0432\u043e, \u043f\u0440\u0430\u0432\u0434\u0430?<\/p>\n<h3>\u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/h3>\n<p>\u0412 \u0432\u0435\u0440\u0441\u0438\u0438 v2 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043f\u0430\u043a\u0435\u0442\u0430, \u043d\u043e \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/p>\n<p>\u0412\u043e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0432 <strong>\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/strong> \u0432 JSON:<\/p>\n<ul>\n<li>\n<p>\u0412 v1 nil-\u0441\u0440\u0435\u0437 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a <code>null<\/code>, \u0432 v2 \u2014 \u043a\u0430\u043a <code>[]<\/code>. \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u0446\u0438\u0435\u0439 <code>FormatNilSliceAsNull<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0412 v1 nil-\u043a\u0430\u0440\u0442\u0430 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a <code>null<\/code>, \u0432 v2 \u2014 \u043a\u0430\u043a <code>{}<\/code>. \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u0446\u0438\u0435\u0439 <code>FormatNilMapAsNull<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0412 v1 \u0431\u0430\u0439\u0442\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043c\u0430\u0441\u0441\u0438\u0432 \u0447\u0438\u0441\u0435\u043b, \u0432 v2 \u2014 \u043a\u0430\u043a base64-\u0441\u0442\u0440\u043e\u043a\u0430. \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u0433\u0430\u043c\u0438 <code>format:array<\/code> \u0438 <code>format:base64<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0412 v1 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 UTF-8 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u0441\u0442\u0440\u043e\u043a\u0435, \u0432 v2 \u2014 \u043d\u0435\u0442. \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u0446\u0438\u0435\u0439 <code>AllowInvalidUTF8<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0443\u043c\u043e\u043b\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f v2:<\/p>\n<pre><code class=\"go\">type Person struct {     Name    string     Hobbies []string     Skills  map[string]int     Secret  [5]byte }  func main() {     alice := Person{         Name:    \"Alice\",         Secret: [5]byte{1, 2, 3, 4, 5},     }     b, _ := json.Marshal(alice, jsontext.Multiline(true))     fmt.Println(string(b)) } <\/code><\/pre>\n<pre><code>{     \"Name\": \"Alice\",     \"Hobbies\": [],     \"Skills\": {},     \"Secret\": \"AQIDBAU=\" } <\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 v1:<\/p>\n<pre><code class=\"go\">type Person struct {     Name    string     Hobbies []string     Skills  map[string]int     Secret  [5]byte `json:\",format:array\"` }  func main() {     alice := Person{         Name:    \"Alice\",         Secret: [5]byte{1, 2, 3, 4, 5},     }     b, _ := json.Marshal(         alice,         json.FormatNilMapAsNull(true),         json.FormatNilSliceAsNull(true),         jsontext.Multiline(true),     )     fmt.Println(string(b)) } <\/code><\/pre>\n<pre><code>{     \"Name\": \"Alice\",     \"Hobbies\": null,     \"Skills\": null,     \"Secret\": [         1,         2,         3,         4,         5     ] } <\/code><\/pre>\n<p>\u0412\u043e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0432 <strong>\u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/strong> \u0438\u0437 JSON:<\/p>\n<ul>\n<li>\n<p>\u0412 v1 \u0438\u043c\u0435\u043d\u0430 \u043f\u043e\u043b\u0435\u0439 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0431\u0435\u0437 \u0443\u0447\u0435\u0442\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430, \u0432 v2 \u2014 \u043f\u043e \u0442\u043e\u0447\u043d\u043e\u043c\u0443 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044e. \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u0446\u0438\u0435\u0439 <code>MatchCaseInsensitiveNames<\/code> \u0438\u043b\u0438 \u0442\u0435\u0433\u043e\u043c <code>case<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0412 v1 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435, \u0432 v2 \u2014 \u043d\u0435\u0442. \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u0446\u0438\u0435\u0439 <code>AllowDuplicateNames<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0443\u043c\u043e\u043b\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f v2 (\u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430):<\/p>\n<pre><code class=\"go\">type Person struct {     FirstName string     LastName  string }  func main() {     src := []byte(`{\"firstname\":\"Alice\",\"lastname\":\"Zakas\"}`)     var alice Person     json.Unmarshal(src, &amp;alice)     fmt.Printf(\"%+v\\n\", alice) } <\/code><\/pre>\n<pre><code>{FirstName: LastName:} <\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 v1 (\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440):<\/p>\n<pre><code class=\"go\">type Person struct {     FirstName string     LastName  string }  func main() {     src := []byte(`{\"firstname\":\"Alice\",\"lastname\":\"Zakas\"}`)     var alice Person     json.Unmarshal(         src, &amp;alice,         json.MatchCaseInsensitiveNames(true),     )     fmt.Printf(\"%+v\\n\", alice) } <\/code><\/pre>\n<pre><code>{FirstName:Alice LastName:Zakas} <\/code><\/pre>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432 <a href=\"https:\/\/pkg.go.dev\/encoding\/json@master#hdr-Migrating_to_v2\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<h3>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/h3>\n<p>\u041f\u0440\u0438 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 v2 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a v1. \u0421 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430\u043c\u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u2014 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435. \u041d\u043e \u043f\u0440\u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0431\u043e\u043b\u044c\u0448\u0430\u044f: v2 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 v1 \u0432 3\u201310 \u0440\u0430\u0437.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u044b\u0445 <code>MarshalJSON<\/code> \u0438 <code>UnmarshalJSON<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u044b\u0435 \u0430\u043d\u0430\u043b\u043e\u0433\u0438 \u2014 <code>MarshalJSONTo<\/code> \u0438 <code>UnmarshalJSONFrom<\/code>. \u041f\u043e \u0441\u043b\u043e\u0432\u0430\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b Go, \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u043d\u0442\u0430\u0439\u043c-\u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u0441 O(n\u00b2) \u0434\u043e O(n). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0441 <code>UnmarshalJSON<\/code> \u043d\u0430 <code>UnmarshalJSONFrom<\/code> \u0434\u043b\u044f OpenAPI-\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 Kubernetes \u0443\u0441\u043a\u043e\u0440\u0438\u043b \u043f\u0440\u043e\u0446\u0435\u0441\u0441 <a href=\"https:\/\/github.com\/kubernetes\/kube-openapi\/issues\/315#issuecomment-1240030015\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 40 \u0440\u0430\u0437<\/a>.<\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u043e\u0432 \u2014\u00a0\u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 <a href=\"https:\/\/github.com\/go-json-experiment\/jsonbench#readme\" rel=\"noopener noreferrer nofollow\">jsonbench<\/a>.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0423\u0444! \u041d\u0435\u0441\u043b\u0430\u0431\u044b\u0439 \u043e\u0431\u044a\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u041f\u0430\u043a\u0435\u0442 v2 \u0431\u043e\u043b\u0435\u0435 \u0444\u0438\u0447\u0430\u0441\u0442\u044b\u0439 \u0438 \u0433\u0438\u0431\u043a\u0438\u0439, \u0447\u0435\u043c v1 \u2014 \u043d\u043e \u043e\u043d \u0438 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0438\u0437-\u0437\u0430 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u0430\u043a\u0435\u0442\u044b <code>json\/v2<\/code> \u0438 <code>jsontext<\/code>.<\/p>\n<p>\u041f\u0430\u0440\u0430 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u043e\u0438\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u0412 Go 1.25 \u043f\u0430\u043a\u0435\u0442 <code>json\/v2<\/code> \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>GOEXPERIMENT=jsonv2<\/code> \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u0431\u043e\u0440\u043a\u0438. API \u043f\u0430\u043a\u0435\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c <code>GOEXPERIMENT=jsonv2<\/code>, \u0442\u043e \u0441\u0442\u0430\u0440\u044b\u0439 \u043f\u0430\u043a\u0435\u0442 <code>json<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u00ab\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c\u00bb.<\/p>\n<\/li>\n<\/ul>\n<p>\u0410 \u0432\u044b \u0447\u0442\u043e \u0434\u0443\u043c\u0430\u0435\u0442\u0435 \u043e <code>json\/v2<\/code>?<\/p>\n<p>P.S. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d Go, \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043c\u043e\u0439 \u043a\u0430\u043d\u0430\u043b <a href=\"https:\/\/t.me\/thank_go\" rel=\"noopener noreferrer nofollow\"><strong>Thank Go<\/strong><\/a>. \u0422\u0430\u043c, \u043a\u0441\u0442\u0430\u0442\u0438, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c \u0438 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0433\u0440\u044f\u0434\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 1.25.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/923404\/\"> https:\/\/habr.com\/ru\/articles\/923404\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u0430 <a href=\"https:\/\/pkg.go.dev\/encoding\/json\/v2\" rel=\"noopener noreferrer nofollow\"><code>json\/v2<\/code><\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 Go 1.25 (\u0430\u0432\u0433\u0443\u0441\u0442 2025) \u2014 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u0412 v2 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 API \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u043b\u0443\u0447\u0448\u0438\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c!<\/p>\n<p>\u0411\u0430\u0437\u043e\u0432\u043e\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>Marshal<\/code> \u0438 <code>Unmarshal<\/code> \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0432 v1, \u0442\u0430\u043a \u0438 \u0432 v2:<\/p>\n<pre><code class=\"go\">type Person struct {     Name string     Age  int } <\/code><\/pre>\n<pre><code class=\"go\">alice := Person{Name: \"Alice\", Age: 25}  \/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0410\u043b\u0438\u0441\u0443. b, err := json.Marshal(alice) fmt.Println(string(b), err)  \/\/ \u0414\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0410\u043b\u0438\u0441\u0443. err = json.Unmarshal(b, &amp;alice) fmt.Println(alice, err) <\/code><\/pre>\n<pre><code>{\"Name\":\"Alice\",\"Age\":25} &lt;nil&gt; {Alice 25} &lt;nil&gt; <\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u043f\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043e\u0442\u043b\u0438\u0447\u0438\u044f\u043c v2 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 v1.<\/p>\n<h3>MarshalWrite \u0438 UnmarshalRead<\/h3>\n<p>\u0412 v1 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 <code>Encoder<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u0438\u0441\u0430\u0442\u044c \u0432 <code>io.Writer<\/code>, \u0438 <code>Decoder<\/code> \u2014 \u0447\u0442\u043e\u0431\u044b \u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0437 <code>io.Reader<\/code>:<\/p>\n<pre><code class=\"go\">\/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0410\u043b\u0438\u0441\u0443. alice := Person{Name: \"Alice\", Age: 25} out := new(strings.Builder) \/\/ io.Writer enc := json.NewEncoder(out) enc.Encode(alice) fmt.Println(out.String())  \/\/ \u0414\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0411\u043e\u0431\u0430. in := strings.NewReader(`{\"Name\":\"Bob\",\"Age\":30}`) \/\/ io.Reader dec := json.NewDecoder(in) var bob Person dec.Decode(&amp;bob) fmt.Println(bob) <\/code><\/pre>\n<pre><code>{\"Name\":\"Alice\",\"Age\":25}  {Bob 30} <\/code><\/pre>\n<blockquote>\n<p>\u042f \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b. \u041d\u0435 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0442\u0430\u043a \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u30c4<\/p>\n<\/blockquote>\n<p>\u0412 v2 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>MarshalWrite<\/code> \u0438 <code>UnmarshalRead<\/code> \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0431\u0435\u0437 \u043f\u043e\u0441\u0440\u0435\u0434\u043d\u0438\u043a\u043e\u0432:<\/p>\n<pre><code class=\"go\">\/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0410\u043b\u0438\u0441\u0443. alice := Person{Name: \"Alice\", Age: 25} out := new(strings.Builder) json.MarshalWrite(out, alice) fmt.Println(out.String())  \/\/ \u0414\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0411\u043e\u0431\u0430. in := strings.NewReader(`{\"Name\":\"Bob\",\"Age\":30}`) var bob Person json.UnmarshalRead(in, &amp;bob) fmt.Println(bob) <\/code><\/pre>\n<pre><code>{\"Name\":\"Alice\",\"Age\":25} {Bob 30 false} <\/code><\/pre>\n<p>\u041d\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435:<\/p>\n<ul>\n<li>\n<p><code>MarshalWrite<\/code> \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0440\u043e\u043a\u0438, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0441\u0442\u0430\u0440\u043e\u0433\u043e <code>Encoder.Encode<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>UnmarshalRead<\/code> \u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0437 \u0440\u0438\u0434\u0435\u0440\u0430 \u0432\u0441\u0435 \u043f\u043e\u0434\u0440\u044f\u0434 \u0434\u043e <code>io.EOF<\/code>, \u0430 \u0441\u0442\u0430\u0440\u044b\u0439 <code>Decoder.Decode<\/code> \u0447\u0438\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 JSON-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<\/ul>\n<h3>MarshalEncode \u0438 UnmarshalDecode<\/h3>\n<p>\u0422\u0438\u043f\u044b <code>Encoder<\/code> \u0438 <code>Decoder<\/code> \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043d\u043e\u0432\u043e\u043c \u043f\u0430\u043a\u0435\u0442\u0435 <a href=\"https:\/\/pkg.go.dev\/encoding\/json\/jsontext\" rel=\"noopener noreferrer nofollow\"><code>jsontext<\/code><\/a>, \u0438 \u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0441\u0438\u043b\u044c\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438\u0441\u044c (\u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f).<\/p>\n<p>\u0418\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 <code>json<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u0447\u043d\u043e \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043f\u0438\u0441\u0430\u0442\u044c JSON, \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043a\u0430\u043a \u0440\u0430\u043d\u044c\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 <code>Encode<\/code> \u0438 <code>Decode<\/code>:<\/p>\n<ul>\n<li>\n<p>v1 <code>Encoder.Encode<\/code> \u2192 v2 <code>json.MarshalEncode<\/code> + <code>jsontext.Encoder<\/code><\/p>\n<\/li>\n<li>\n<p>v1 <code>Decoder.Decode<\/code> \u2192 v2 <code>json.UnmarshalDecode<\/code> + <code>jsontext.Decoder<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a:<\/p>\n<pre><code class=\"go\">people := []Person{     {Name: \"Alice\", Age: 25},     {Name: \"Bob\", Age: 30},     {Name: \"Cindy\", Age: 15}, } out := new(strings.Builder) enc := jsontext.NewEncoder(out)  for _, p := range people {     \/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442 Person \u0437\u0430 \u0432\u044b\u0437\u043e\u0432.     json.MarshalEncode(enc, p) }  fmt.Print(out.String()) <\/code><\/pre>\n<pre><code>{\"Name\":\"Alice\",\"Age\":25} {\"Name\":\"Bob\",\"Age\":30} {\"Name\":\"Cindy\",\"Age\":15} <\/code><\/pre>\n<p>\u041f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u0434\u0435\u043a\u043e\u0434\u0435\u0440:<\/p>\n<pre><code class=\"go\">in := strings.NewReader(`     {\"Name\":\"Alice\",\"Age\":25}     {\"Name\":\"Bob\",\"Age\":30}     {\"Name\":\"Cindy\",\"Age\":15} `) dec := jsontext.NewDecoder(in)  for {     var p Person     \/\/ \u0414\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442 Person \u0437\u0430 \u0432\u044b\u0437\u043e\u0432.     err := json.UnmarshalDecode(dec, &amp;p)     if err == io.EOF {         break     }     fmt.Println(p) } <\/code><\/pre>\n<pre><code>{Alice 25} {Bob 30} {Cindy 15} <\/code><\/pre>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <code>UnmarshalRead<\/code>, \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>UnmarshalDecode<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u2014 \u043e\u043d\u0430 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0437\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0437\u043e\u0432, \u0430 \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u0442 \u0432\u0441\u0435 \u0441\u0440\u0430\u0437\u0443 \u0434\u043e <code>io.EOF<\/code>.<\/p>\n<h3>\u041e\u043f\u0446\u0438\u0438<\/h3>\n<p>\u041e\u043f\u0446\u0438\u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442 \u043d\u044e\u0430\u043d\u0441\u044b \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><code>FormatNilMapAsNull<\/code> \u0438 <code>FormatNilSliceAsNull<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442, \u043a\u0430\u043a \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c nil-\u043a\u0430\u0440\u0442\u044b \u0438 \u0441\u0440\u0435\u0437\u044b.<\/p>\n<\/li>\n<li>\n<p><code>MatchCaseInsensitiveNames<\/code> \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u043c\u0435\u043d\u0430 \u0431\u0435\u0437 \u0443\u0447\u0435\u0442\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>Name<\/code> \u2194 <code>name<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>Multiline<\/code> \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 JSON-\u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a.<\/p>\n<\/li>\n<li>\n<p><code>OmitZeroStructFields<\/code> \u0443\u0431\u0438\u0440\u0430\u0435\u0442 \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u043e\u043b\u044f \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p><code>SpaceAfterColon<\/code> \u0438 <code>SpaceAfterComma<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442 \u043f\u0440\u043e\u0431\u0435\u043b \u043f\u043e\u0441\u043b\u0435 <code>:<\/code> \u0438\u043b\u0438 <code>,<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>StringifyNumbers<\/code> \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0447\u0438\u0441\u043b\u0430 \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><code>WithIndent<\/code> \u0438 <code>WithIndentPrefix<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442 \u043e\u0442\u0441\u0442\u0443\u043f\u044b \u0434\u043b\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 (\u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>MarshalIndent<\/code> \u0432 v2 \u0443\u0434\u0430\u043b\u0435\u043d\u0430).<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0446\u0438\u0439:<\/p>\n<pre><code class=\"go\">alice := Person{Name: \"Alice\", Age: 25} b, _ := json.Marshal(     alice,     json.OmitZeroStructFields(true),     json.StringifyNumbers(true),     jsontext.WithIndent(\"  \"), ) fmt.Println(string(b)) <\/code><\/pre>\n<pre><code>{   \"Name\": \"Alice\",   \"Age\": \"25\" } <\/code><\/pre>\n<p>\u041e\u043f\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>JoinOptions<\/code>:<\/p>\n<pre><code class=\"go\">alice := Person{Name: \"Alice\", Age: 25} opts := json.JoinOptions(     jsontext.SpaceAfterColon(true),     jsontext.SpaceAfterComma(true), ) b, _ := json.Marshal(alice, opts) fmt.Println(string(b)) <\/code><\/pre>\n<pre><code>{\"Name\": \"Alice\", \"Age\": 25} <\/code><\/pre>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u043f\u0446\u0438\u0439 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438: \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 <a href=\"https:\/\/pkg.go.dev\/encoding\/json\/v2#Options\" rel=\"noopener noreferrer nofollow\"><code>json<\/code><\/a>, \u0434\u0440\u0443\u0433\u0438\u0435 \u2014 \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 <a href=\"https:\/\/pkg.go.dev\/encoding\/json\/jsontext#Options\" rel=\"noopener noreferrer nofollow\"><code>jsontext<\/code><\/a>.<\/p>\n<h3>\u0422\u0435\u0433\u0438<\/h3>\n<p>v2 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u0435\u0433\u0438 \u043f\u043e\u043b\u0435\u0439 \u0438\u0437 v1:<\/p>\n<ul>\n<li>\n<p><code>omitzero<\/code> \u0438 <code>omitempty<\/code> \u2014 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p><code>string<\/code> \u2014 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><code>-<\/code> \u2014 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e:<\/p>\n<ul>\n<li>\n<p><code>case:ignore<\/code> \u0438 <code>case:strict<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435.<\/p>\n<\/li>\n<li>\n<p><code>format:template<\/code> \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443.<\/p>\n<\/li>\n<li>\n<p><code>inline<\/code> \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u044b\u0432\u043e\u0434 \u00ab\u043f\u043b\u043e\u0441\u043a\u0438\u043c\u00bb, \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044f \u043f\u043e\u043b\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><code>unknown<\/code> \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u0435 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0432 \u043e\u0434\u043d\u043e.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f <code>inline<\/code> \u0438 <code>format<\/code>:<\/p>\n<pre><code class=\"go\">type Person struct {     Name string         `json:\"name\"`     \/\/ \u0424\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u0442\u0443 \u043a\u0430\u043a \u0433\u0433\u0433\u0433-\u043c\u043c-\u0434\u0434.     BirthDate time.Time `json:\"birth_date,format:DateOnly\"`     \/\/ \u0412\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u043e\u043b\u044f \u0430\u0434\u0440\u0435\u0441\u0430 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 Person.     Address             `json:\",inline\"` }  type Address struct {     Street string `json:\"street\"`     City   string `json:\"city\"` }  func main() {     alice := Person{         Name: \"Alice\",         BirthDate: time.Date(2001, 7, 15, 12, 35, 43, 0, time.UTC),         Address: Address{             Street: \"123 Main St\",             City:   \"Wonderland\",         },     }     b, _ := json.Marshal(alice, jsontext.WithIndent(\"  \"))     fmt.Println(string(b)) } <\/code><\/pre>\n<pre><code>{   \"name\": \"Alice\",   \"birth_date\": \"2001-07-15\",   \"street\": \"123 Main St\",   \"city\": \"Wonderland\" } <\/code><\/pre>\n<p>\u0418 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f <code>unknown<\/code>:<\/p>\n<pre><code class=\"go\">type Person struct {     Name string         `json:\"name\"`     \/\/ \u0421\u043e\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043f\u043e\u043b\u044f Person     \/\/ \u0432 \u043f\u043e\u043b\u0435 Data.     Data map[string]any `json:\",unknown\"` }  func main() {     src := `{         \"name\": \"Alice\",         \"hobby\": \"adventure\",         \"friends\": [             {\"name\": \"Bob\"},             {\"name\": \"Cindy\"}         ]     }`     var alice Person     json.Unmarshal([]byte(src), &amp;alice)     fmt.Println(alice) } <\/code><\/pre>\n<pre><code>{Alice map[friends:[map[name:Bob] map[name:Cindy]] hobby:adventure]} <\/code><\/pre>\n<h3>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440\u044b<\/h3>\n<p>\u041a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b <code>Marshaler<\/code> \u0438 <code>Unmarshaler<\/code>. \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0432 v1, \u0442\u0430\u043a \u0438 \u0432 v2:<\/p>\n<pre><code class=\"go\">\/\/ \u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0438\u043f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \/\/ true \u2014 \u044d\u0442\u043e \"\u2713\", \u0430 false \u2014 \"\u2717\". type Success bool  func (s Success) MarshalJSON() ([]byte, error) {     if s {         return []byte(`\"\u2713\"`), nil     }     return []byte(`\"\u2717\"`), nil }  func (s *Success) UnmarshalJSON(data []byte) error {     \/\/ \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u0430 \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438.     *s = string(data) == `\"\u2713\"`     return nil }  func main() {     \/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c true -&gt; \u2713.     val := Success(true)     data, err := json.Marshal(val)     fmt.Println(string(data), err)      \/\/ \u0414\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u2713 -&gt; true.     src := []byte(`\"\u2713\"`)     err = json.Unmarshal(src, &amp;val)     fmt.Println(val, err) } <\/code><\/pre>\n<pre><code>\"\u2713\" &lt;nil&gt; true &lt;nil&gt; <\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0441\u043e\u0432\u0435\u0442\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b <code>MarshalerTo<\/code> \u0438 <code>UnmarshalerFrom<\/code> (\u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435):<\/p>\n<pre><code class=\"go\">\/\/ \u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0438\u043f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \/\/ true \u2014 \u044d\u0442\u043e \"\u2713\", \u0430 false \u2014 \"\u2717\". type Success bool  func (s Success) MarshalJSONTo(enc *jsontext.Encoder) error {     if s {         return enc.WriteToken(jsontext.String(\"\u2713\"))     }     return enc.WriteToken(jsontext.String(\"\u2717\")) }  func (s *Success) UnmarshalJSONFrom(dec *jsontext.Decoder) error {     \/\/ \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u0430 \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438.     tok, err := dec.ReadToken()     *s = tok.String() == `\"\u2713\"`     return err }  func main() {     \/\/ \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c true -&gt; \u2713.     val := Success(true)     data, err := json.Marshal(val)     fmt.Println(string(data), err)      \/\/ \u0414\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u2713 -&gt; true.     src := []byte(`\"\u2713\"`)     err = json.Unmarshal(src, &amp;val)     fmt.Println(val, err) } <\/code><\/pre>\n<pre><code>\"\u2713\" &lt;nil&gt; true &lt;nil&gt; <\/code><\/pre>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0432\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u044b \u043e\u0434\u043d\u0438\u043c \u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440\u043e\u043c (\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u043c) \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440\u044b \u0438 \u0430\u043d\u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440\u044b \u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u2014 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>MarshalFunc<\/code> \u0438 <code>UnmarshalFunc<\/code>.<\/p>\n<pre><code class=\"go\">func MarshalFunc[T any](fn func(T) ([]byte, error)) *Marshalers func UnmarshalFunc[T any](fn func([]byte, T) error) *Unmarshalers <\/code><\/pre>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>bool<\/code> \u0432 <code>\u2713<\/code> \u0438\u043b\u0438 <code>\u2717<\/code> \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"go\">\/\/ \u041a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. boolMarshaler := json.MarshalFunc(     func(val bool) ([]byte, error) {         if val {             return []byte(`\"\u2713\"`), nil         }         return []byte(`\"\u2717\"`), nil     }, )  \/\/ \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0432 Marshal \/\/ \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0446\u0438\u0438 WithMarshalers. val := true data, err := json.Marshal(val, json.WithMarshalers(boolMarshaler)) fmt.Println(string(data), err) <\/code><\/pre>\n<pre><code>\"\u2713\" &lt;nil&gt; <\/code><\/pre>\n<p>\u0418 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>\u2713<\/code> \u0438\u043b\u0438 <code>\u2717<\/code> \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 <code>bool<\/code>:<\/p>\n<pre><code class=\"go\">\/\/ \u0414\u0435\u043a\u043e\u0434\u0435\u0440 \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. boolUnmarshaler := json.UnmarshalFunc(     func(data []byte, val *bool) error {         *val = string(data) == `\"\u2713\"`         return nil     }, )  \/\/ \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u0432 \u0432 Unmarshal \/\/ \u0447\u0435\u0440\u0435\u0437 \u043e\u043f\u0446\u0438\u044e WithUnmarshalers. src := []byte(`\"\u2713\"`) var val bool err := json.Unmarshal(src, &amp;val, json.WithUnmarshalers(boolUnmarshaler)) fmt.Println(val, err) <\/code><\/pre>\n<pre><code>true &lt;nil&gt; <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u0432 \u0438 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u043e\u0432 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0442\u0430\u043a\u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>MarshalToFunc<\/code> \u0438 <code>UnmarshalFromFunc<\/code>. \u041e\u043d\u0438 \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 <code>MarshalFunc<\/code> \u0438 <code>UnmarshalFunc<\/code>, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 <code>jsontext.Encoder<\/code> \u0438 <code>jsontext.Decoder<\/code>, \u0430 \u043d\u0435 \u0441 \u0431\u0430\u0439\u0442\u043e\u0432\u044b\u043c\u0438 \u0441\u0440\u0435\u0437\u0430\u043c\u0438.<\/p>\n<pre><code class=\"go\">func MarshalToFunc[T any](fn func(*jsontext.Encoder, T) error) *Marshalers func UnmarshalFromFunc[T any](fn func(*jsontext.Decoder, T) error) *Unmarshalers <\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>JoinMarshalers<\/code> (\u0438 \u0430\u043d\u043c\u0430\u0440\u0448\u0430\u043b\u0435\u0440\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>JoinUnmarshalers<\/code>). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (<code>true<\/code>\/<code>false<\/code>) \u0438<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-465238","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/465238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=465238"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/465238\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=465238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=465238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=465238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}