use yaml for parsing JSON - works without quotes on simple strings
This commit is contained in:
parent
9bb027ed4c
commit
00a6e70430
6 changed files with 29 additions and 28 deletions
|
@ -1,7 +1,8 @@
|
|||
package rep
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
//"encoding/json"
|
||||
json "gopkg.in/yaml.v3"
|
||||
|
||||
"git.sr.ht/~cco/go-scopes/logging/log"
|
||||
)
|
||||
|
|
3
go.mod
3
go.mod
|
@ -6,8 +6,8 @@ require (
|
|||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/lib/pq v1.10.9
|
||||
github.com/rs/zerolog v1.29.1
|
||||
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090
|
||||
golang.org/x/net v0.10.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
modernc.org/sqlite v1.25.0
|
||||
)
|
||||
|
||||
|
@ -41,7 +41,6 @@ require (
|
|||
golang.org/x/text v0.9.0 // indirect
|
||||
golang.org/x/tools v0.6.0 // indirect
|
||||
google.golang.org/protobuf v1.30.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
lukechampine.com/uint128 v1.2.0 // indirect
|
||||
modernc.org/cc/v3 v3.40.0 // indirect
|
||||
modernc.org/ccgo/v3 v3.16.13 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -90,8 +90,6 @@ golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
|
|||
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
|
||||
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
|
||||
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 h1:Di6/M8l0O2lCLc6VVRWhgCiApHV8MnQurBnFSHsQtNY=
|
||||
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
|
||||
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
|
||||
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||
|
|
|
@ -68,6 +68,7 @@ func init() {
|
|||
HeadFields: hf,
|
||||
IdFields: hf,
|
||||
Indexes: ixs,
|
||||
InsertOnChange: true,
|
||||
}
|
||||
tracking.RegisterContainerDef(container_definition)
|
||||
}
|
||||
|
|
|
@ -92,6 +92,7 @@ type ContDef struct {
|
|||
HeadFields lib.StrSlice
|
||||
IdFields lib.StrSlice
|
||||
Indexes []lib.StrSlice
|
||||
InsertOnChange bool
|
||||
}
|
||||
|
||||
type Container struct {
|
||||
|
@ -321,6 +322,7 @@ func init() {
|
|||
HeadFields: hf,
|
||||
IdFields: hf,
|
||||
Indexes: ixs,
|
||||
InsertOnChange: true,
|
||||
}
|
||||
RegisterContainerDef(container_definition)
|
||||
}
|
||||
|
|
|
@ -70,12 +70,12 @@ func RepTest(t *testing.T) {
|
|||
}
|
||||
|
||||
func JsonTest(t *testing.T) {
|
||||
j := `[4, 2, "+"]`
|
||||
j := `[4, 2, +]`
|
||||
src := rep.ParseJson(j)
|
||||
c := src.Compile(fe)
|
||||
fe.Call(c)
|
||||
t.AssertEqual(fe.Pop(), 6)
|
||||
j = `{"firstname": "John", "lastname": "Dow"}`
|
||||
j = `{firstname: John, lastname: Dow}`
|
||||
prep := rep.ParseJsonTo[Person](j)
|
||||
person := prep.(*rep.Record).Data().(Person)
|
||||
t.AssertEqual(person.FirstName, "John")
|
||||
|
|
Loading…
Add table
Reference in a new issue