@@ -35,9 +35,10 @@ func (s SpecError) Error() string {
3535// Config contains the options that dictate the behavior of a transform. The internal
3636// `spec` object can be an arbitrary json configuration for the transform.
3737type Config struct {
38- Spec * map [string ]interface {} `json:"spec"`
39- Require bool `json:"require,omitempty"`
40- InPlace bool `json:"inplace,omitempty"`
38+ Spec * map [string ]interface {} `json:"spec"`
39+ Require bool `json:"require,omitempty"`
40+ InPlace bool `json:"inplace,omitempty"`
41+ KeySeparator string `json:"keySeparator"`
4142}
4243
4344var (
4647)
4748
4849// Given a json byte slice `data` and a kazaam `path` string, return the object at the path in data if it exists.
49- func getJSONRaw (data []byte , path string , pathRequired bool ) ([]byte , error ) {
50- objectKeys := strings .Split (path , "." )
50+ func getJSONRaw (data []byte , path string , pathRequired bool , keySeparator string ) ([]byte , error ) {
51+ objectKeys := strings .Split (path , keySeparator )
5152 numOfInserts := 0
5253 for element , k := range objectKeys {
5354 // check the object key to see if it also contains an array reference
@@ -64,7 +65,7 @@ func getJSONRaw(data []byte, path string, pathRequired bool) ([]byte, error) {
6465 // ArrayEach setup
6566 objectKeys [element + numOfInserts ] = objKey
6667 beforePath := objectKeys [:element + numOfInserts + 1 ]
67- newPath := strings .Join (objectKeys [element + numOfInserts + 1 :], "." )
68+ newPath := strings .Join (objectKeys [element + numOfInserts + 1 :], keySeparator )
6869 var results [][]byte
6970
7071 // use jsonparser.ArrayEach to copy the array into results
@@ -82,7 +83,7 @@ func getJSONRaw(data []byte, path string, pathRequired bool) ([]byte, error) {
8283 // GetJSONRaw() the rest of path for each element in results
8384 if newPath != "" {
8485 for i , value := range results {
85- intermediate , err := getJSONRaw (value , newPath , pathRequired )
86+ intermediate , err := getJSONRaw (value , newPath , pathRequired , keySeparator )
8687 if err == jsonparser .KeyPathNotFoundError {
8788 if pathRequired {
8889 return nil , NonExistentPath
@@ -137,11 +138,10 @@ func getJSONRaw(data []byte, path string, pathRequired bool) ([]byte, error) {
137138}
138139
139140// setJSONRaw sets the value at a key and handles array indexing
140- func setJSONRaw (data , out []byte , path string ) ([]byte , error ) {
141+ func setJSONRaw (data , out []byte , path , keySeparator string ) ([]byte , error ) {
141142 var err error
142- splitPath := strings .Split (path , "." )
143+ splitPath := strings .Split (path , keySeparator )
143144 numOfInserts := 0
144-
145145 for element , k := range splitPath {
146146 arrayRefs := jsonPathRe .FindAllStringSubmatch (k , - 1 )
147147 if arrayRefs != nil && len (arrayRefs ) > 0 {
@@ -158,7 +158,7 @@ func setJSONRaw(data, out []byte, path string) ([]byte, error) {
158158 // ArrayEach setup
159159 splitPath [element + numOfInserts ] = objKey
160160 beforePath := splitPath [:element + numOfInserts + 1 ]
161- afterPath := strings .Join (splitPath [element + numOfInserts + 1 :], "." )
161+ afterPath := strings .Join (splitPath [element + numOfInserts + 1 :], keySeparator )
162162 // use jsonparser.ArrayEach to count the number of items in the
163163 // array
164164 var arraySize int
@@ -175,18 +175,18 @@ func setJSONRaw(data, out []byte, path string) ([]byte, error) {
175175 // iterate through each item in the array by replacing the
176176 // wildcard with an int and joining the path back together
177177 newArrayKey := strings .Join ([]string {"[" , strconv .Itoa (i ), "]" }, "" )
178- beforePathStr := strings .Join (beforePath , "." )
178+ beforePathStr := strings .Join (beforePath , keySeparator )
179179 beforePathArrayKeyStr := strings .Join ([]string {beforePathStr , newArrayKey }, "" )
180180 // if there's nothing that comes after the array index,
181181 // don't join so that we avoid trailing cruft
182182 if len (afterPath ) > 0 {
183- newPath = strings .Join ([]string {beforePathArrayKeyStr , afterPath }, "." )
183+ newPath = strings .Join ([]string {beforePathArrayKeyStr , afterPath }, keySeparator )
184184 } else {
185185 newPath = beforePathArrayKeyStr
186186 }
187187 // now call the function, but this time with an array index
188188 // instead of a wildcard
189- data , err = setJSONRaw (data , out , newPath )
189+ data , err = setJSONRaw (data , out , newPath , keySeparator )
190190 if err != nil {
191191 return nil , err
192192 }
@@ -209,9 +209,9 @@ func setJSONRaw(data, out []byte, path string) ([]byte, error) {
209209}
210210
211211// delJSONRaw deletes the value at a path and handles array indexing
212- func delJSONRaw (data []byte , path string , pathRequired bool ) ([]byte , error ) {
212+ func delJSONRaw (data []byte , path string , pathRequired bool , keySeparator string ) ([]byte , error ) {
213213 var err error
214- splitPath := strings .Split (path , "." )
214+ splitPath := strings .Split (path , keySeparator )
215215 numOfInserts := 0
216216
217217 for element , k := range splitPath {
0 commit comments