JSON Scalar throws 'couldNotConvert'


I’m trying to fetch JSON Scalar data from an API, but it’s being decoded as a String and it fails. The data I’m waiting for is of type: [String: Int].

This is the error message:

couldNotConvert(value: AnyHashable([AnyHashable(“stringValue1”): AnyHashable(5), AnyHashable(“stringValue2”): AnyHashable(5), AnyHashable(“stringValue3”): AnyHashable(5), AnyHashable(“stringValue4”): AnyHashable(5), AnyHashable(“stringValue5”): AnyHashable(4), AnyHashable(“stringValue6”): AnyHashable(5), AnyHashable(“stringValue7”): AnyHashable(5), AnyHashable(“stringValue8”): AnyHashable(5), AnyHashable(“stringValue9”): AnyHashable(5), AnyHashable(“stringValue10”): AnyHashable(5)]), to: Swift.String)

What can I do?

Thank you.

@Javi_Gallego By default the extension generated for a custom scalar has it as a String however you can customize that extension to match whatever type you need and handle the decoding. Our docs page here has some examples of how to do this.