Skip to content

encoding/json: how to marshal with unicode escape? #39137

@cupen

Description

@cupen

What version of Go are you using (go version)?

$ go version
go version go1.14.2 linux/amd64

What did you expect to see?

module json add a API for marshal string with unicode escape would be useful.

unicode escape
https://tools.ietf.org/html/rfc7159#section-7

package main

import (
	"fmt"
	"encoding/json"
)

type Object struct {
	Name string
}

func main() {
	obj := Object{Name:"哇呀呀"}
	line, _ := json.MarshalUnicodeEscape(obj)
	fmt.Println(string(line))
}
{"Name": "\u54c7\u5440\u5440"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions