Skip to content

Commit

Permalink
Document the json filter's indent argument [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
jg-rp committed Jan 22, 2025
1 parent 6666c72 commit 75d2eef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
- Updated filters `map`, `where`, `sort`, `sort_natural`, `uniq`, `compact` and `sum` to accept lambda expression or string arguments.
- Added filters `reject`, `has`, `find` and `find_index`.

**Documentation**

- Added documentation for the `json` filter's optional `indent` argument.

## Version 0.2.0

**Features**
Expand Down
32 changes: 29 additions & 3 deletions docs/filter_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ John Paul George Ringo
<!-- md:liquid2 -->

```
<object> | json
<object> | json[: <indent>]
```

Return the input object serialized to a JSON (JavaScript Object Notation) string.
Expand All @@ -1050,6 +1050,21 @@ Return the input object serialized to a JSON (JavaScript Object Notation) string
{ "id": 1234, "name": "Football" }
```

### Pretty JSON

If an argument is given, it should be an integer defining the amount of indentation that should be applied to a formatted JSON representation of the input object.

```liquid2
{{ product | json: indent=2 }}
```

```plain title="output"
{
"id": 1234,
"name": "Football"
}
```

## last

<!-- md:version 0.1.0 -->
Expand Down Expand Up @@ -2437,9 +2452,20 @@ In this example we select pages that have a "coding" tag.

```liquid2
{% assign coding_pages = pages | where: page => page.tags contains 'coding' %}
{{ coding_pages | map: page => page.title | json }}
{{ coding_pages | json: indent=2}}
```

```plain title="output"
["Mastering JavaScript"]
[
{
"id": 3,
"title": "Mastering JavaScript",
"category": "Programming",
"tags": [
"JavaScript",
"web development",
"coding"
]
}
]
```

0 comments on commit 75d2eef

Please sign in to comment.