Skip to content

Commit

Permalink
Merge pull request #259 from octonawish-akcodes/str
Browse files Browse the repository at this point in the history
added pretty json support example
  • Loading branch information
Peefy authored Jan 31, 2024
2 parents d9a98c1 + 0cabe0a commit 33636ab
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/user_docs/support/faq-kcl.md
Original file line number Diff line number Diff line change
Expand Up @@ -2352,3 +2352,32 @@ schema Data:
check:
environment in allowed, "environment must be one of {}".format(allowed)
```

## 52. How to output pretty json string in KCL?

KCL has in-built support for getting formatted JSON strings. Here's how you can do it:

Paste the below content in your main.k file.

```python
import json

config = {
key1 = "value1"
key2 = "value2"
}
configJson = json.encode(config, ignore_private=True, indent=4)
```

After running this code, `configJson` variable will contain a prettified JSON string.

```json
config:
key1: value1
key2: value2
configJson: |-
{
"key1": "value1",
"key2": "value2"
}
```

0 comments on commit 33636ab

Please sign in to comment.