- pure Go
- no Javascript
- no dependencies
- no
reflect
- no
fmt
- 300 LOC
- customizable rendering
- JSON Path for elements access
// JSON has to be any
var v any
json.Unmarshal(exampleJSON, &v)
htmlPage := htmljson.DefaultPageMarshalerm.Marshal(v)
// JSON has to be any
var v any
json.Unmarshal(exampleJSON, &v)
// customize how to render HTML elements
s := htmljson.Marshaler{
Null: htmljson.NullHTML,
Bool: htmljson.BoolHTML,
String: htmljson.StringHTML,
Number: func(k string, v float64, s string) string {
if k == "$.cakes.strawberry-cake.size" {
return `<div class="json-value json-number" style="color:red;">` + s + `</div>`
}
if v > 10 {
return `<div class="json-value json-number" style="color:blue;">` + s + `</div>`
}
return `<div class="json-value json-number">` + s + `</div>`
},
Array: htmljson.DefaultArrayHTML,
Map: htmljson.DefaultMapHTML,
Row: htmljson.DefaultRowHTML{Padding: 4}.Marshal,
}
m := htmljson.DefaultPageMarshaler
m.Marshaler = &s
// write HTML page
htmlPage := m.Marshal(v)
- https://github.com/alecthomas/chroma can render many languages into HTML with syntax highligting