https://github.com/thinkalexandria/elm-pretty-print-json
Pretty print JSON with nesting indents into a String
https://github.com/thinkalexandria/elm-pretty-print-json
elm-lang json pretty-print
Last synced: about 1 year ago
JSON representation
Pretty print JSON with nesting indents into a String
- Host: GitHub
- URL: https://github.com/thinkalexandria/elm-pretty-print-json
- Owner: ThinkAlexandria
- License: bsd-3-clause
- Created: 2018-05-10T15:01:31.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-04-20T20:53:54.000Z (about 5 years ago)
- Last Synced: 2025-04-13T03:07:45.830Z (about 1 year ago)
- Topics: elm-lang, json, pretty-print
- Language: Elm
- Size: 3.91 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-pretty-print-json
Pretty print JSON encoded as a String or as `Json.Encode.Value` with nesting
indents.
Useful for implementing JSON editors, where you want to format the JSON before
initializing a ``
## Example
Take a string containing JSON and format it with 4 space indents.
```elm
json = """{"name": "Arnold", "age": 70, "isStrong": true,"knownWeakness": null,"nicknames": ["Terminator", "The Governator"],"extra": {"foo": "bar","zap": {"cat": 1,"dog": 2},"transport": [[ "ford", "chevy" ],[ "TGV", "bullet train", "steam" ]]}}"""
indent = 4
Result.withDefault "" (Json.Print.prettyString indent json)
{-
{
"extra": {
"transport": [
[
"ford",
"chevy"
],
[
"TGV",
"bullet train",
"steam"
]
],
"zap": {
"dog": 2,
"cat": 1
},
"foo": "bar"
},
"nicknames": [
"Terminator",
"The Governator"
],
"knownWeakness": null,
"isStrong": true,
"age": 70,
"name": "Arnold"
}
-}
```