1
0
mirror of https://github.com/a-h/templ.git synced 2025-02-06 10:03:16 +00:00
templ/jsonstring.go
Adrian Hesketh 85a7b8b19a
feat: add JSONString and JSONScript functions, update docs, refer to templ script as legacy in docs (#745)
Co-authored-by: Joe Davidson <joe.davidson.21111@gmail.com>
2024-05-21 14:27:08 +01:00

15 lines
224 B
Go

package templ
import (
"encoding/json"
)
// JSONString returns a JSON encoded string of v.
func JSONString(v any) (string, error) {
b, err := json.Marshal(v)
if err != nil {
return "", err
}
return string(b), nil
}