Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nikolaydubina/htmljson
🫐 Rich rendering of JSON as HTML in Go
https://github.com/nikolaydubina/htmljson
code-editor code-formatting code-visualization data-formatting go golang html json rendering test-editor visualization
Last synced: 20 days ago
JSON representation
🫐 Rich rendering of JSON as HTML in Go
- Host: GitHub
- URL: https://github.com/nikolaydubina/htmljson
- Owner: nikolaydubina
- License: mit
- Created: 2023-03-18T04:10:28.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-03-21T11:31:40.000Z (8 months ago)
- Last Synced: 2024-05-01T14:34:55.523Z (7 months ago)
- Topics: code-editor, code-formatting, code-visualization, data-formatting, go, golang, html, json, rendering, test-editor, visualization
- Language: Go
- Homepage:
- Size: 561 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-go - htmljson - Rich rendering of JSON as HTML in Go. (JSON / Search and Analytic Databases)
README
## 🫐 htmljson: rich rendering of JSON as HTML in Go
[![codecov](https://codecov.io/gh/nikolaydubina/htmljson/branch/master/graph/badge.svg?token=yXmNdIDn8O)](https://codecov.io/gh/nikolaydubina/htmljson)
[![Go Report Card](https://goreportcard.com/badge/github.com/nikolaydubina/htmljson)](https://goreportcard.com/report/github.com/nikolaydubina/htmljson)
[![Go Reference](https://pkg.go.dev/badge/github.com/nikolaydubina/htmljson.svg)](https://pkg.go.dev/github.com/nikolaydubina/htmljson)
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/nikolaydubina/htmljson/badge)](https://securityscorecards.dev/viewer/?uri=github.com/nikolaydubina/htmljson)* pure Go
* no Javascript
* no dependencies
* no `reflect`
* no `fmt`
* 300 LOC
* customizable rendering
* JSON Path for elements access![](./doc/example-color.png)
```go
// JSON has to be any
var v any
json.Unmarshal(exampleJSON, &v)htmlPage := htmljson.DefaultPageMarshalerm.Marshal(v)
``````go
// 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 `` + s + ``
}
if v > 10 {
return `` + s + ``
}
return `` + s + ``
},
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)
```## Related Work
- https://github.com/alecthomas/chroma can render many languages into HTML with syntax highligting