valyala / fastjson

Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any way to get the _raw_ bytes from the key? (GetRaw("key"))

salmonix opened this issue · comments

Get("key").String() returns the json string removing the escape characters, while GetStringByte("key") does the same only converting it into a []byte, as

[]byte( Get("key").String() ) ==  GetStringByte("key") 

This raw value, for instance,

<?xml version=\"1.0\" encoding=\"UTF-8\"?>

is turned into

 <?xml version="1.0" encoding="UTF-8"?>

The unescaped value can not be Set directly in the json:

Set("key", fastjson.MustParseBytes(value) ) 

will return error.

This behavior prevents low level modification of the value. For example, replacing placeholders in a bigger xml without parsing the xml data, then re-escaping it would add unnecessary overhead to the whole operation.
Is there any way to retrieve the value in its raw []byte form ?