https://github.com/seeadoog/jsonpath-reverse
Jsonpath-reverse is a tool used for creating json reversed by expression like jsonpath for go.
https://github.com/seeadoog/jsonpath-reverse
jsonpath jsonpath-reverse
Last synced: 4 months ago
JSON representation
Jsonpath-reverse is a tool used for creating json reversed by expression like jsonpath for go.
- Host: GitHub
- URL: https://github.com/seeadoog/jsonpath-reverse
- Owner: seeadoog
- Created: 2019-01-04T10:46:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-30T01:54:09.000Z (8 months ago)
- Last Synced: 2024-11-30T16:12:25.654Z (6 months ago)
- Topics: jsonpath, jsonpath-reverse
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
#### josnref for go
**usage**
jsonpath-reverse is a tool used for creating jsonpath reversed. with this tool ,you can create a json string by specific query string like "$.user.name"
and set a value like 'bob' to it. The tool will generate a json string such as follow:
```text
{
"user":{
"name":"bob"
}
}
```**get start**
- install
```text
go get -t github.com/seeadoog/jsonpath-reverse
```- use
```text
import (
"fmt"
"encoding/json"
jsonref "github.com/skyniu/jsonpath-reverse"
)
type User struct {
Name string `json:"name"`
Age int `json:"age"`
}func main() {
jp, err := Compile("a.name[0]")
if err != nil {
panic(err)
}var a any
err = jp.Set(&a, 1)
if err != nil {
panic(err)
}
ns, _ := json.MarshalIndent(a, "", " ")
fmt.Println(string(ns))
}```
the output json is :
```text
{
"a": {
"name": [
1
]
}
}
```