Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Dim newMap As Map = CreateMap()
Dim key As String = "aKey"
' Dim value As Object = CreateMap("aaa": 1, "bbb": 2)
' Dim value As Object = Array As String("aaa", "bbb")
Dim value As Object = "aaa"
If value Is Map Then
newMap.Put(key, CopyMap(value))
Else If value Is List Then
newMap.Put(key, CopyList(value))
Else
newMap.Put(key, value) ' Direct copy for simple types
End If
Log(newMap.Get("aKey")) '{aaa=1, bbb=2} or '[aaa, bbb] or 'aaa respectively
End Sub
Private Sub CopyMap(mp As Map) As Map 'a simplistic stand-in for the OP's Sub - assumes that elements of the map are basic types
Dim result As Map
result.Initialize
For Each kw As String In mp.keys
result.Put(kw, mp.Get(kw))
Next
Return result
End Sub
Private Sub CopyList(lst As List) As List 'a simplistic stand-in for the OP's Sub - assumes that elements of the list are basic types
Dim result As List
result.Initialize
For Each obj As Object In lst
result.Add(obj)
Next
Return result
End Sub