Skip to content

Commit

Permalink
docs(transformer-json): clean up readme (#7889)
Browse files Browse the repository at this point in the history
  • Loading branch information
macklinu authored and m-allanson committed Sep 5, 2018
1 parent 7b0a555 commit c1f4f9c
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions packages/gatsby-transformer-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ or as single objects spread across multiple files.

The algorithm for arrays is to convert each item in the array into a node.

So if your project has a `letters.json` with `[{ "value": "a" }, { "value": "b" }, { "value": "c" }]` then the following three nodes would be created:
So if your project has a `letters.json` with

```javascript
;[{ value: "a" }, { value: "b" }, { value: "c" }]
```json
[{ "value": "a" }, { "value": "b" }, { "value": "c" }]
```

Then the following three nodes would be created:

```json
[{ "value": "a" }, { "value": "b" }, { "value": "c" }]
```

### Single Object
Expand All @@ -49,7 +55,7 @@ The algorithm for single JSON objects is to convert the object defined at the
root of the file into a node. The type of the node is based on the name of the
parent directory.

For example, lets say your project has a data layout like:
For example, let's say your project has a data layout like:

```
data/
Expand All @@ -61,31 +67,31 @@ data/

Where each of `a.json`, `b.json` and `c.json` look like:

```javascript
{ 'value': 'a' }
```json
{ "value": "a" }
```

```javascript
{ 'value': 'b' }
```json
{ "value": "b" }
```

```javascript
{ 'value': 'c' }
```json
{ "value": "c" }
```

Then the following three nodes would be created:

```javascript
;[
```json
[
{
value: "a",
"value": "a"
},
{
value: "b",
"value": "b"
},
{
value: "c",
},
"value": "c"
}
]
```

Expand Down Expand Up @@ -144,24 +150,18 @@ If some fields are missing or you see the error on build:
It's probably because you have arrays of mixed values somewhere. For instance:

```
```json
{
stuff: [25, "bob"],
orEven: [
[25, "bob"],
[23, "joe"]
]
"stuff": [25, "bob"],
"orEven": [[25, "bob"], [23, "joe"]]
}
```

If you can rewrite your data with objects you should be good to go:
If you can rewrite your data with objects, you should be good to go:

```
```json
{
stuff: [{ "count": 25, "name": "bob" }],
orEven: [
{ "count": 25, "name": "bob" },
{ "count": 23, "name": "joe" }
]
"stuff": [{ "count": 25, "name": "bob" }],
"orEven": [{ "count": 25, "name": "bob" }, { "count": 23, "name": "joe" }]
}
```

0 comments on commit c1f4f9c

Please sign in to comment.