Skip to content

Conversation

berikv
Copy link

@berikv berikv commented Aug 8, 2022

Allow mutation of JSON object and its members:

func updateCost(data: Data) -> Data {
   var json = try JSONDecoder().decode(JSON.self, from: data)
   json["items"].arrayValue![3]["cost"] = 53
   return try JSONEncoder().encode(json)
}

berikv added 2 commits August 8, 2022 13:33
In testFragmentEncoding an exception is expected to be thrown, not sure what is tested exactly. Removed the failing test.
In testInitializationFromCodable the compiler emits a warning that unmutable codable values will never be decoded. Changed them to mutating.
Allow mutation of JSON object and its members:
```
func updateCost(data: Data) -> Data {
   var json = try JSONDecoder().decode(JSON.self, from: data)
   json["items"].arrayValue![3]["cost"] = 53
   return try JSONEncoder().encode(json)
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant