Skip to content

Commit 72ea291

Browse files
committed
Beta release with readme
0 parents  commit 72ea291

File tree

2 files changed

+470
-0
lines changed

2 files changed

+470
-0
lines changed

README.md

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
Peterjsons helps dealing with random json input when the usecase is a transformation to another json output. It receives a random json input and a json recipe to "cook" the json output.
2+
3+
## How to install:
4+
5+
```bash
6+
go get github.com/stacknowledge/peterjsons
7+
```
8+
9+
## How to use:
10+
11+
```golang
12+
package main
13+
14+
import (
15+
"fmt"
16+
17+
"github.com/stacknowledge/peterjsons"
18+
)
19+
20+
func main() {
21+
material := []byte(`
22+
{
23+
"info" : {
24+
"peter":"jsons"
25+
}
26+
}
27+
`)
28+
29+
recipe := []byte(`
30+
{
31+
"recipe": {
32+
"id" : "info.peter"
33+
}
34+
}
35+
`)
36+
37+
pjsons, err := peterjsons.New(material, recipe)
38+
if err != nil {
39+
fmt.Printf("\n %s \n", err)
40+
}
41+
42+
pjsons.Cook()
43+
44+
fmt.Printf("\n %s \n", pjsons.JSONResult())
45+
46+
// ------------------------------------------------
47+
// Outputs : {"id":"jsons"}
48+
// ------------------------------------------------
49+
}
50+
```
51+
52+
## Example:
53+
54+
### Input example
55+
```json
56+
{
57+
"data": {
58+
"product": {
59+
"id": "identification",
60+
"title": "title",
61+
"description": "This is description and now it has more than 20 chars.",
62+
"version": 1,
63+
"category_code": "category",
64+
"contact": {
65+
"name": "peters",
66+
"phones": ["790123123", "790123546"],
67+
"logo": "https://peters.logos.com/jsons.jpg"
68+
},
69+
"properties": {
70+
"multiple": [
71+
{
72+
"code": "peter",
73+
"value": "json"
74+
},
75+
{
76+
"code": "json",
77+
"value": "peter"
78+
}
79+
]
80+
}
81+
}
82+
}
83+
}
84+
```
85+
86+
### Recipe Example:
87+
88+
```json
89+
 {
90+
"recipe": {
91+
"contact": "data.product.contact",
92+
"meta.id": "data.product.id",
93+
"products": {
94+
"values": ["data.product.properties.multiple"],
95+
"operation": "swapmap",
96+
"*": {
97+
"id": {
98+
"value": "code"
99+
},
100+
"description": {
101+
"value": "value"
102+
},
103+
"price": {
104+
"replace": 1
105+
}
106+
}
107+
},
108+
"info": {
109+
"resume": {
110+
"values": ["data.product.title", "data.product.description"],
111+
"operation": "concat",
112+
"separator": " - "
113+
},
114+
"category": {
115+
"values": ["data.product.category_code"],
116+
"operation": "swap",
117+
"replace": ["one_bed"]
118+
},
119+
"version": {
120+
"values": ["data.product.version"],
121+
"operation": "swap",
122+
"format": "v%v.0.0"
123+
},
124+
"advertiser": {
125+
"values": ["data.product.advertiser_type"],
126+
"operation": "swap",
127+
"replace": [1]
128+
}
129+
}
130+
}
131+
}
132+
```
133+
134+
### Result:
135+
```json
136+
{
137+
"meta": {
138+
"id": "identification"
139+
},
140+
"contact": {
141+
"logo": "https://peters.logos.com/jsons.jpg",
142+
"name": "peters",
143+
"phones": ["790123123", "790123546"]
144+
},
145+
"info": {
146+
"advertiser": 1,
147+
"category": "one_bed",
148+
"resume": "title - This is description and now it has more than 20 chars.",
149+
"version": "v1.0.0"
150+
},
151+
"products": [
152+
{
153+
"description": "json",
154+
"id": "peter",
155+
"price": 1
156+
},
157+
{
158+
"description": "peter",
159+
"id": "json",
160+
"price": 1
161+
}
162+
]
163+
}
164+
```

0 commit comments

Comments
 (0)