Skip to content

Commit

Permalink
added pretty json support example
Browse files Browse the repository at this point in the history
Signed-off-by: Abhishek Kumar <[email protected]>
  • Loading branch information
octonawish-akcodes committed Jan 31, 2024
1 parent 1309213 commit 0cabe0a
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 0cabe0a

Please sign in to comment.