Skip to content

Commit 34fdfe1

Browse files
authored
Fix various spelling mistakes (#4)
1 parent 16ce338 commit 34fdfe1

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ A library for decoding and encoding json, built on top of @pointfreeco's [Parsin
2727

2828
## Introduction
2929

30-
As mentioned above, this library is built using the [Parsing](https://github.com/pointfreeco/swift-parsing) library, which is a library that provides a consistent story for writing _parsing_ code in Swift, that is, code that turns some _unstructured data_ into more _structured data_. You do that by constructing _parsers_ that are generic over both the (unstructured) _input_ and the (structued) _output_. What's really great is the fact the these parsers can be made _invertible_ (or bidirectional), meaning thay can also turn structured data _back_ into unstructed data, referred to as _printing_.
30+
As mentioned above, this library is built using the [Parsing](https://github.com/pointfreeco/swift-parsing) library, which is a library that provides a consistent story for writing _parsing_ code in Swift, that is, code that turns some _unstructured data_ into more _structured data_. You do that by constructing _parsers_ that are generic over both the (unstructured) _input_ and the (structued) _output_. What's really great is the fact the these parsers can be made _invertible_ (or bidirectional), meaning they can also turn structured data _back_ into unstructured data, referred to as _printing_.
3131

3232
The *JSONParsing* library provides predefined parsers tuned specifically for when the _input is json_, giving you a convenient way of writing parsers capable of parsing (decoding) and printing (encoding) json. This style of dealing with json has a number of benefits compared to the *Codable* abstraction. More about that in the [Motivation](#motivation---why-not-use-codable) section.
3333

@@ -145,7 +145,7 @@ Or perhaps:
145145
"205,99,138"
146146
```
147147

148-
The truth is, both representations are reasonable (as well as many other possibilities), and it's possible that you might have one API endpoint returning RGB colors in the first format, and another in the second format. But when using Codable, you would have to choose one of the formats to be the one used for the `RGBColor` type. To handle both variants, you would have to define two separate types, something like `RGBColorWithObjectRepresentaion` and `RGBColorWithStringRepresentation`, and conform both of them to `Codable`, with the different decoding/encoding strategies.
148+
The truth is, both representations are reasonable (as well as many other possibilities), and it's possible that you might have one API endpoint returning RGB colors in the first format, and another in the second format. But when using Codable, you would have to choose one of the formats to be the one used for the `RGBColor` type. To handle both variants, you would have to define two separate types, something like `RGBColorWithObjectRepresentation` and `RGBColorWithStringRepresentation`, and conform both of them to `Codable`, with the different decoding/encoding strategies.
149149

150150
Using the *JSONParsing* library, you can easily just create two separate parsers, one for each alternative:
151151

@@ -284,15 +284,15 @@ print(String(data: encodedJson, encoding: .utf8)!)
284284

285285
### Decoding and encoding logic out of sync
286286

287-
Codable has the really cool feature of being able to automatically sythesize the decoding and encoding implementations for Swift types, thanks to integration with the Swift compiler. Unfortunately, in practice, the automatically synthesized implementations will often not be correct for your usecase, because it assumes that your json data and your Swift data types _exactly_ match each other in structure. This will often not be the case, for various reasons. First, you might be dealing with JSON APIs that you don't own yourself and therefore might deliver data in a format that isn't ideal to your usecase. But even if you do own the API code, it might be used by multiple platforms, which means you can't tailor it specifically to work perfectly with your Swift code. Also, Swift has some features, such as enums, that simply _can't_ be expressed equivalently in json.
287+
Codable has the really cool feature of being able to automatically synthesize the decoding and encoding implementations for Swift types, thanks to integration with the Swift compiler. Unfortunately, in practice, the automatically synthesized implementations will often not be correct for your use case, because it assumes that your json data and your Swift data types _exactly_ match each other in structure. This will often not be the case, for various reasons. First, you might be dealing with JSON APIs that you don't own yourself and therefore might deliver data in a format that isn't ideal to your use case. But even if you do own the API code, it might be used by multiple platforms, which means you can't tailor it specifically to work perfectly with your Swift code. Also, Swift has some features, such as enums, that simply _can't_ be expressed equivalently in json.
288288

289289
So in practice, when using Codable, you will often have to implement the decoding and encoding logic manually. And the problem in that situation, is that they have to be implemented _separately_. This means that, whenever the expected json format changes in any way, you have to remember to update both the `init(from:)` (decoding) and the `encode(to:)` (encoding) implementations accordingly.
290290

291291
With *JSONParsing* on the other hand, you can write a single json parser that can take care of both the decoding and the encoding (as was shown in the [Quick start](#quick-start) section). What this means is that you are guaranteed to always have the two transformations kept in sync as your json API evolves.
292292

293293
### Custom String parsing
294294

295-
Recall how we previously defined a json parser for the `RGBColor` type, where the json representation was a comma seperated string. It looked like this:
295+
Recall how we previously defined a json parser for the `RGBColor` type, where the json representation was a comma separated string. It looked like this:
296296

297297
```swift
298298
extension RGBColor {
@@ -539,7 +539,7 @@ public enum JSONValue: Equatable {
539539

540540
So when we call the `decode(_:)` and `encode(_:)` methods on the parsers, the decoding and encoding happens in two steps: the json data is transformed to/from the `JSONValue` type, and the `JSONValue` type is in turn transformed to/from the result type using the `Parser.parse`/`ParserPrinter.print` methods.
541541

542-
The primary usecase for the `JSONValue` type is just to act as this middle layer, to simplify the implementations of the various json parsers that ship with the library. However, it can actually be useful on its own. For instance, you might have code like this today:
542+
The primary use case for the `JSONValue` type is just to act as this middle layer, to simplify the implementations of the various json parsers that ship with the library. However, it can actually be useful on its own. For instance, you might have code like this today:
543543

544544
```swift
545545
let json: [String: Any] = [
@@ -591,7 +591,7 @@ let json: [String: Any] = [
591591

592592
This library ships with a number of json parsers, that can be composed together to deal with more complex json structures. As mentioned in the previous section, they all take values of the custom type `JSONValue` as input, so when using the `parse`/`print` methods, they convert to/from that type.
593593

594-
When you want to use them to decode/encode json _data_ (which is likely to be the most common usecase) you just use the `decode`/`encode` methods defined on them instead, which does the converting to from data for you.
594+
When you want to use them to decode/encode json _data_ (which is likely to be the most common use case) you just use the `decode`/`encode` methods defined on them instead, which does the converting to from data for you.
595595

596596
### Null
597597

@@ -1061,7 +1061,7 @@ try Person.jsonParser.print(person2)
10611061
// .object(["first_name": "Mark", "last_name": "Markson", "age": 20])
10621062
```
10631063

1064-
Instead of treating an abscent value as `nil`, you can optionally provide a `default` value, to use as a fallback:
1064+
Instead of treating an absent value as `nil`, you can optionally provide a `default` value, to use as a fallback:
10651065

10661066
```diff
10671067
struct Person {
@@ -1141,7 +1141,7 @@ extension Person {
11411141

11421142
### Integrating *JSONParsing* into *Codable* code
11431143

1144-
So that's one part of the equation, when it comes to integration with Codable. But what about the other way around? What if we actually _do_ have a json parser capable of decoding `Movie`s, and we're using Codable for the `Person` type instead. For that usecase, the library comes with overloads of the various methods on the decoding/encoding containers, that take a json parser as input. Let's see what it looks like to use this, by conforming the `Person` type to both the `Decodable` and the `Encodable` protocol:
1144+
So that's one part of the equation, when it comes to integration with Codable. But what about the other way around? What if we actually _do_ have a json parser capable of decoding `Movie`s, and we're using Codable for the `Person` type instead. For that use case, the library comes with overloads of the various methods on the decoding/encoding containers, that take a json parser as input. Let's see what it looks like to use this, by conforming the `Person` type to both the `Decodable` and the `Encodable` protocol:
11451145

11461146
```swift
11471147
extension Person: Decodable {

Sources/JSONParsing/JSONParsers/Field.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22
import Parsing
33

4-
/// A parser that tries to parse off a single field from a json object. The parser, if succesful, will remove the field from the input json,
4+
/// A parser that tries to parse off a single field from a json object. The parser, if successful, will remove the field from the input json,
55
/// so that it can then be further parsed by other parsers.
66
///
77
/// For example, here's how to work with a json value that encodes a person. First, let's see how a single `Field` parser
@@ -84,7 +84,7 @@ public struct Field<Value: Parser>: Parser where Value.Input == JSONValue {
8484
/// The parser to apply to the value of the field.
8585
public let valueParser: Value
8686

87-
/// Initializes a parser that tries to parse off a single field from a json object. The parser, if succesful, will remove the field from
87+
/// Initializes a parser that tries to parse off a single field from a json object. The parser, if successful, will remove the field from
8888
/// the input json, so that it can then be further parsed by other parsers.
8989
///
9090
/// Here's how it can be used to parse the individual fields of a json representing a `Person`:

Sources/JSONParsing/JSONParsers/JSONObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ where Key.Input == Substring, Key.Output: Hashable, Value.Input == JSONValue {
5656
/// Initialize a parser that tries to parse a json value as an object, and turn it into a Swift `Dictionary` value.
5757
///
5858
/// You can provide an optional `range` to limit the number of key/value pair that are accepted,
59-
/// as well as indvidual parsers to be used for the _keys_ and the _values_ respectively.
59+
/// as well as individual parsers to be used for the _keys_ and the _values_ respectively.
6060
///
6161
/// For example, image that you want to parse a json that looks something like this:
6262
///

Sources/JSONParsing/JSONParsers/OptionalField.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Parsing
44
/// A parser that, like the ``Field`` parser, tries to parse off a single field from a json object.
55
/// But unlike the `Field` parser, it allows for the field to _not exists_, in which case it just
66
/// returns `nil` or a `default` value if one is provided. Just like the `Field` parser it will,
7-
/// if succesful, remove the field (if existent) from the input json.
7+
/// if successful, remove the field (if existent) from the input json.
88
///
99
/// **Note: the `OptionalField` parser treats a field with an explicit `null` value as non-existent.**
1010
///

Tests/JSONParsingTests/JSONValue/PrettyPrintingTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class PrettyPrintingTests: XCTestCase {
2121
XCTAssertEqual(json.prettyPrinted(maxDepth: 0), "{ \"a\": true }")
2222
}
2323

24-
func testMaxSubvalueCount0() {
24+
func testMaxSubValueCount0() {
2525
let json = JSONValue.object([
2626
"key1": .boolean(true),
2727
"key2": .string("hello"),

0 commit comments

Comments
 (0)