Skip to content

Commit daef3e9

Browse files
committed
Merge branch 'main' of https://github.com/frikky/schemaless
2 parents 2375a7c + a66e5ec commit daef3e9

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ go get github.com/frikky/schemaless
1515
```
1616

1717
```
18-
output := schemaless.Translate(ctx context.Context, standard string, userinput string)
18+
// Translate random string -> JSON paths
19+
output := schemaless.Translate(ctx context.Context, standard string, userinput string)
20+
21+
// Translate outputted data -> standard location
22+
output, err := ReverseTranslate(sourceMap, searchInMap)
1923
```
2024

2125
## Test it
@@ -63,3 +67,54 @@ This is an example that finds matching nested values based on the User Input and
6367
}
6468
```
6569

70+
71+
## Reverse Example
72+
There are however cases where you have done translation from input data to output data, but don't have a reference of how the translation between them happened. In this case, we built a reverse translation search which also outputs the path in the same way. This e.g. allows us to NOT keep using AI translation after it's been done once, and instead override the translation itself with just a JSON reference.
73+
74+
**Outputted data:**
75+
```
76+
{
77+
"findme": "This is the value to find",
78+
"subkey": {
79+
"findAnother": "This is another value to find",
80+
"subsubkey": {
81+
"findAnother2": "Amazing subsubkey to find"
82+
},
83+
"sublist": [
84+
"This is a list",
85+
"This is a list",
86+
"Cool list item",
87+
"This is a list"
88+
],
89+
"objectlist": [{
90+
"key1": "This is a key"
91+
},
92+
{
93+
"key1": "Another cool thing"
94+
}]
95+
}
96+
}`
97+
```
98+
99+
**The standard with the data locations to find:**
100+
```
101+
{
102+
"key1": "This is the value to find",
103+
"key2": "This is another value to find",
104+
"key3": "Amazing subsubkey to find",
105+
"key4": "Cool list item",
106+
"key5": "Another cool thing"
107+
}
108+
```
109+
110+
111+
**Expected Output**:
112+
```
113+
{
114+
"key1": "findme",
115+
"key2": "subkey.findAnother",
116+
"key3": "subkey.subsubkey.findAnother2",
117+
"key5": "subkey.objectlist.#1.key1",
118+
"key4": "subkey.sublist.#2"
119+
}
120+
```

0 commit comments

Comments
 (0)