Helper method used when splicing literal json strings.
Helper method used when splicing literal json strings.
This avoids the extra commas which would otherwise occur when we splice an empty Iterable or Option. There are three cases to consider:
val xs = Nil json"[ ..$xs, 2 ]" - leading comma json"[ 1, ..$xs, 2]" - double comma json"[ 1, ..$xs ]" - trailing comma
To handle the first case, we check when adding a segment beginning with a comma whether the last character was a list or object opener. If so, we drop the comma.
To handle the latter two cases, we check when adding a segment whether the last character was a comma and the next character is a comma or object or list closer. If so, we drop the last comma added.