Skip to content

Commit de5173b

Browse files
authored
Update README.md
1 parent 625e143 commit de5173b

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,33 @@ SQL Server 2016 has the new feature of creating JSON output using FOR JSON claus
77

88
In the deploy folder open JSONBeautifier.sql and run the code in the same order. At the end of the script there are some examples provided on how to use this function.
99

10+
### How to use the function
1011

12+
This is a scalar function which will take the JSON string as input and provide the formatted \ beautified \ intended JSON output.
1113

14+
#### Example 1
15+
16+
Pass the JSON value from a query into the function.
17+
18+
```
19+
SELECT [dbo].[IndentJSON](
20+
LTRIM
21+
(
22+
(
23+
SELECT TOP 2 A.ADDRESSID
24+
,A.CITY AS "REGION.CITY"
25+
,A.COUNTRYREGION AS "REGION.COUNTRYREGION"
26+
FROM ADVENTUREWORKSLT2012.SALESLT.ADDRESS A
27+
FOR JSON PATH , ROOT('Region')
28+
)
29+
)
30+
)
31+
```
32+
33+
#### Example 2
34+
35+
Pass the string directly in the function. This string can be assigned to a variable and passed as a parameter.
36+
37+
```
38+
SELECT [dbo].[IndentJSON]('{"id": 1,"name": "A green door","price": 12.50,"tags": ["home", "green"]}')
39+
```

0 commit comments

Comments
 (0)