Skip to content

Commit cfeb203

Browse files
committed
Use delimiter in converting to JSON
1 parent 55c91df commit cfeb203

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sources/ToJSON.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
import class Foundation.NSNumber
3030

3131
private func setValue(_ value: Any, map: Map) {
32-
setValue(value, key: map.currentKey!, checkForNestedKeys: map.keyIsNested, dictionary: &map.JSON)
32+
setValue(value, key: map.currentKey!, checkForNestedKeys: map.keyIsNested, delimiter: map.nestedKeyDelimiter, dictionary: &map.JSON)
3333
}
3434

35-
private func setValue(_ value: Any, key: String, checkForNestedKeys: Bool, dictionary: inout [String : Any]) {
35+
private func setValue(_ value: Any, key: String, checkForNestedKeys: Bool, delimiter: String, dictionary: inout [String : Any]) {
3636
if checkForNestedKeys {
37-
let keyComponents = ArraySlice(key.characters.split { $0 == "." })
37+
let keyComponents = ArraySlice(key.components(separatedBy: delimiter).filter { !$0.isEmpty }.map { $0.characters })
3838
setValue(value, forKeyPathComponents: keyComponents, dictionary: &dictionary)
3939
} else {
4040
dictionary[key] = value

0 commit comments

Comments
 (0)