Skip to content

Support mutating JSON values #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Support mutating JSON values #37

wants to merge 2 commits into from

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