Skip to content

Commit 3e95d45

Browse files
committed
More schemaless parsing magic
1 parent 70ac390 commit 3e95d45

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

translate.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ func handleMultiListItems(translatedInput []interface{}, parentKey string, parse
932932
} else if val, ok := v.(string); ok {
933933
log.Printf("string: %s", childKey)
934934
if strings.Contains(val, "schemaless_list[") {
935-
log.Printf("SCHEMALESS LIST FOUND")
935+
log.Printf("SCHEMALESS LIST FOUND: %s", val)
936936

937937
foundList := strings.Split(val, "schemaless_list")
938938
if len(foundList) >= 2 {
@@ -943,23 +943,21 @@ func handleMultiListItems(translatedInput []interface{}, parentKey string, parse
943943
}
944944

945945
log.Printf("Keys: %d", len(unmarshalledList))
946-
if len(translatedInput) < len(unmarshalledList) {
947946

948-
// Reference Item
949-
firstItem := translatedInput[0]
950-
for cnt, listValue := range unmarshalledList {
951-
if cnt >= len(translatedInput) {
952-
translatedInput = append(translatedInput, firstItem)
953-
}
947+
// Reference Item
948+
firstItem := translatedInput[0]
949+
for cnt, listValue := range unmarshalledList {
950+
if cnt >= len(translatedInput) {
951+
translatedInput = append(translatedInput, firstItem)
952+
}
954953

955-
// Update the translatedInput with the new value
956-
newKey := fmt.Sprintf("%s.%s", parentKey, childKey)
957-
// Remove the first key
958-
newKey = strings.SplitN(newKey, ".", 2)[1]
959-
translatedInput[cnt] = setNestedMap(translatedInput[cnt].(map[string]interface{}), newKey, listValue)
954+
// Update the translatedInput with the new value
955+
newKey := fmt.Sprintf("%s.%s", parentKey, childKey)
956+
// Remove the first key
957+
newKey = strings.SplitN(newKey, ".", 2)[1]
958+
translatedInput[cnt] = setNestedMap(translatedInput[cnt].(map[string]interface{}), newKey, listValue)
960959

961-
log.Printf("\n\nCNT: %d, NewKey: %s, ListValue: %s\n\n", cnt, newKey, listValue)
962-
}
960+
log.Printf("\n\nCNT: %d, NewKey: %s, ListValue: %s\n\n", cnt, newKey, listValue)
963961
}
964962
}
965963
}
@@ -969,7 +967,6 @@ func handleMultiListItems(translatedInput []interface{}, parentKey string, parse
969967
}
970968
}
971969

972-
log.Printf("TRANSLATEDINPUT: %#v", translatedInput)
973970
return translatedInput
974971
}
975972

@@ -1062,7 +1059,6 @@ func runJsonTranslation(ctx context.Context, inputValue []byte, translation map[
10621059

10631060
// Hard to optimise for subkeys -> parent control tho
10641061
if strings.Contains(string(output), "schemaless_list[") {
1065-
log.Printf("WHAT IS THE KEY HERE? %#v. Output: %s", translationKey, output)
10661062
newTranslatedInput := handleMultiListItems(newOutput, translationKey, outputParsed)
10671063
translationValue = newTranslatedInput
10681064

0 commit comments

Comments
 (0)