-1

I am trying to initialize a JSON object as a byte in go lang. Here, I am attaching two exmples

var countryRegionData = []byte(`{"name": "srinivas"}`)

var countryRegionData = []byte(`{"name": "srini`vas"}`)

In the first initilization there is no issue, all working as expected.

In the second initialization if you see there is ` between i and v. I have some requirement like this. How to achieve?

Srinivas
  • 294
  • 3
  • 18
  • 1
    Does this answer your question? [how to put a backquote in a backquoted string?](https://stackoverflow.com/questions/4423951/how-to-put-a-backquote-in-a-backquoted-string) – Brits Oct 14 '20 at 05:43

2 Answers2

0

A backtick cannot appear in a raw string literal. You can write something like this:

var countryRegionData = []byte("{\"name\": \"srini`vas\"}")
Henry
  • 42,982
  • 7
  • 68
  • 84
0

You cannot use escaping in a raw string literal. Either you have to use double-quoted string:

"{\"name\": \"srini'vas\"}"

Or do something like:

`{"name": "srini`+"`"+"vas"}`
Burak Serdar
  • 46,455
  • 3
  • 40
  • 59