source: frontend/node_modules/flatted/golang/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.1 KB
Line 
1# flatted (Go)
2
3A super light and fast circular JSON parser.
4
5## Usage
6
7```go
8package main
9
10import (
11 "fmt"
12 "github.com/WebReflection/flatted/golang/pkg/flatted"
13)
14
15type Group struct {
16 Name string `json:"name"`
17}
18
19type User struct {
20 Name string `json:"name"`
21 Friend *User `json:"friend"`
22 Group *Group `json:"group"`
23}
24
25func main() {
26 group := &Group{Name: "Developers"}
27 alice := &User{Name: "Alice", Group: group}
28 bob := &User{Name: "Bob", Group: group}
29
30 alice.Friend = bob
31 bob.Friend = alice // Circular reference
32
33 // Stringify Alice
34 s, _ := flatted.Stringify(alice)
35 fmt.Println(s)
36 // Output: [{"name":"Alice","friend":"1","group":"2"},{"name":"Bob","friend":"0","group":"2"},{"name":"Developers"}]
37
38 // Flattening in action:
39 // Index "0" is Alice, Index "1" is Bob, Index "2" is the shared Group.
40
41 // Parse back into a generic map structure
42 res, _ := flatted.Parse(s)
43 aliceMap := res.(map[string]any)
44 fmt.Println(aliceMap["name"]) // Alice
45}
46```
47
48## CLI
49
50Build the binary using the provided Makefile:
51
52```bash
53make build
54```
55
56Then use it to parse flatted JSON from stdin:
57
58```bash
59echo '[{"a":"1"},"b"]' | ./flatted
60```
Note: See TracBrowser for help on using the repository browser.