...
1 package jsonschemax
2
3 import (
4 "net/url"
5 "strings"
6
7 "github.com/pkg/errors"
8 )
9
10
11 func JSONPointerToDotNotation(pointer string) (string, error) {
12 if !strings.HasPrefix(pointer, "#/") {
13 return pointer, errors.Errorf("remote JSON pointers are not supported: %s", pointer)
14 }
15
16 var path []string
17 for _, item := range strings.Split(strings.TrimPrefix(pointer, "#/"), "/") {
18 item = strings.Replace(item, "~1", "/", -1)
19 item = strings.Replace(item, "~0", "~", -1)
20 item, err := url.PathUnescape(item)
21 if err != nil {
22 return "", err
23 }
24 path = append(path, strings.ReplaceAll(item, ".", "\\."))
25 }
26
27 return strings.Join(path, "."), nil
28 }
29
View as plain text