So I have JSON, which has string keys and values which can be either strings or custom JSON, when I put json there (even if I put it in quotes) JSONDecoder throws an error "The given data was not valid JSON.", when there is a string everything is okay, is there maybe some decodable extension which can help with that? Coding Keys unfortunately not an option here. Example of json
"""
{
"someKey":"{
"key1":"value1",
"key2":"value2"
}"
}
"""
Decoding simply as
try JSONDecoder().decode([String: String].self, from: json)
First, there are quotes to remove :
Secondly, you will have to provide a more exact model :
JSONDecoder is not really designed for JSON with unknown model. If you would like to parse JSON for which you do not know the model before, you will have to use another library. I personnally use https://github.com/zoul/generic-json-swift .