Skip to content

Commit 242fc45

Browse files
committed
initial commit
0 parents  commit 242fc45

File tree

13 files changed

+2303
-0
lines changed

13 files changed

+2303
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: "pages"
15+
cancel-in-progress: false
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: 'stable'
28+
29+
- name: Build WASM
30+
run: |
31+
GOOS=js GOARCH=wasm go build -o public/jsonforms.wasm main.go
32+
33+
- name: Download wasm_exec.js
34+
run: |
35+
curl -sL "https://raw.githubusercontent.com/golang/go/release-branch.go1.21/misc/wasm/wasm_exec.js" -o public/wasm_exec.js
36+
37+
- name: Setup Pages
38+
uses: actions/configure-pages@v4
39+
40+
- name: Upload artifact
41+
uses: actions/upload-pages-artifact@v3
42+
with:
43+
path: './public'
44+
45+
deploy:
46+
environment:
47+
name: github-pages
48+
url: ${{ steps.deployment.outputs.page_url }}
49+
runs-on: ubuntu-latest
50+
needs: build
51+
steps:
52+
- name: Deploy to GitHub Pages
53+
id: deployment
54+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.wasm

.golangci.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
version: '2'
2+
linters:
3+
enable:
4+
- asasalint
5+
- asciicheck
6+
- bidichk
7+
- bodyclose
8+
- containedctx
9+
- contextcheck
10+
- copyloopvar
11+
- decorder
12+
- dogsled
13+
- err113
14+
- exhaustive
15+
- fatcontext
16+
- gocheckcompilerdirectives
17+
- goconst
18+
- gomoddirectives
19+
- govet
20+
- iface
21+
- ineffassign
22+
- interfacebloat
23+
- intrange
24+
- makezero
25+
- mirror
26+
- misspell
27+
- nestif
28+
- nilerr
29+
- nilnesserr
30+
- noctx
31+
- nonamedreturns
32+
- nosprintfhostport
33+
- protogetter
34+
- staticcheck
35+
- tagalign
36+
- testifylint
37+
- unconvert
38+
- unparam
39+
- unused
40+
- wastedassign
41+
- wsl_v5
42+
43+
settings:
44+
gomoddirectives:
45+
go-version-pattern: '1\.\d+(\.0)?$'
46+
replace-local: true
47+
replace-allow-list:
48+
- google.golang.org/genproto

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# JSON Forms HTML Renderer
2+
3+
A WebAssembly-powered web application that converts JSON Forms schemas into semantic HTML forms. Runs entirely in your browser with no server required.
4+
5+
## 🚀 [Try it Live](https://tinybluerobots.github.io/jsonforms-html/)
6+
7+
## Usage
8+
9+
Paste your JSON in this format:
10+
11+
```json
12+
{
13+
"schema": {
14+
"type": "object",
15+
"properties": {
16+
"name": { "type": "string", "title": "Full Name" },
17+
"email": { "type": "string", "format": "email" }
18+
},
19+
"required": ["name"]
20+
},
21+
"uischema": {
22+
"type": "VerticalLayout",
23+
"elements": [
24+
{ "type": "Control", "scope": "#/properties/name" },
25+
{ "type": "Control", "scope": "#/properties/email" }
26+
]
27+
}
28+
}
29+
```
30+
31+
Click "Generate HTML" to see the rendered form.
32+
33+
## Building
34+
35+
```bash
36+
GOOS=js GOARCH=wasm go build -o public/jsonforms.wasm main.go
37+
```
38+
39+
## Dependencies
40+
41+
- [jsonforms-parser](https://github.com/tinybluerobots/jsonforms-parser) - JSON Forms AST parser
42+
43+
## Related
44+
45+
- [JSON Forms](https://jsonforms.io/) - Official JavaScript implementation

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/tinybluerobots/jsonforms-html
2+
3+
go 1.25
4+
5+
require github.com/tinybluerobots/jsonforms-parser v0.0.0-20251116100119-5179f92695d5

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
6+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
7+
github.com/tinybluerobots/jsonforms-parser v0.0.0-20251116100119-5179f92695d5 h1:zTFFq8ymUiaVBqqyt7axjkf3thy7L23mSVGa3uCFXRE=
8+
github.com/tinybluerobots/jsonforms-parser v0.0.0-20251116100119-5179f92695d5/go.mod h1:J7OikK6WCqCYHqkWDdxb89DvYEU4gMAIlajuw07LOdg=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//go:build js && wasm
2+
3+
package main
4+
5+
import (
6+
"encoding/json"
7+
"syscall/js"
8+
9+
ast "github.com/tinybluerobots/jsonforms-parser"
10+
"github.com/tinybluerobots/jsonforms-html/renderer"
11+
)
12+
13+
func renderHTML(this js.Value, args []js.Value) interface{} {
14+
if len(args) != 1 {
15+
return map[string]interface{}{
16+
"error": "renderHTML expects 1 argument: JSON string with schema and uischema",
17+
}
18+
}
19+
20+
jsonString := args[0].String()
21+
22+
// Parse the input JSON
23+
var input struct {
24+
Schema json.RawMessage `json:"schema"`
25+
UISchema json.RawMessage `json:"uischema"`
26+
}
27+
28+
if err := json.Unmarshal([]byte(jsonString), &input); err != nil {
29+
return map[string]interface{}{
30+
"error": "Invalid JSON: " + err.Error(),
31+
}
32+
}
33+
34+
// Validate we have both schema and uischema
35+
if len(input.Schema) == 0 || len(input.UISchema) == 0 {
36+
return map[string]interface{}{
37+
"error": "JSON must contain both 'schema' and 'uischema' properties",
38+
}
39+
}
40+
41+
// Parse using jsonforms-parser
42+
tree, err := ast.Parse(input.UISchema, input.Schema)
43+
if err != nil {
44+
return map[string]interface{}{
45+
"error": "Failed to parse schemas: " + err.Error(),
46+
}
47+
}
48+
49+
// Render to HTML
50+
html, err := renderer.Render(tree, nil)
51+
if err != nil {
52+
return map[string]interface{}{
53+
"error": "Failed to render HTML: " + err.Error(),
54+
}
55+
}
56+
57+
return map[string]interface{}{
58+
"html": html,
59+
}
60+
}
61+
62+
func main() {
63+
// Make the Go function available to JavaScript
64+
js.Global().Set("renderHTML", js.FuncOf(renderHTML))
65+
66+
// Keep the program running
67+
select {}
68+
}

mise.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tools]
2+
golangci-lint = "2"
3+
gotestsum = "latest"

0 commit comments

Comments
 (0)