Xml_To_Json
Converts an XML to a JSON string
- Free Function
- SQL Server Compatibility: 2008, 2012, 2014, 2016, 2017
SELECT SQLHTTP.net.Xml_To_Json ( @Xml )
Name | Type | Description |
---|---|---|
@Xml | xml | An XML value to be converted to a JSON string |
nvarchar(MAX)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
DECLARE @Json nvarchar(MAX) DECLARE @X xml SET @X = '<?xml version="1.0" encoding="UTF-8"?> <DocumentElement param="value"> <FirstElement> ¶ Some Text </FirstElement> <?some_pi some_attr="some_value"?> <SecondElement param2="something"> Pre-Text <Inline>Inlined text</Inline> Post-text. </SecondElement> </DocumentElement>' SET @Json = SQLHTTP.net.Xml_To_Json(@X) SELECT SQLHTTP.net.FormatJson(@Json) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
------------------------------------------------ { "DocumentElement": { "FirstElement": "¶ Some Text", "SecondElement": { "Inline": "Inlined text", "param2": "something", "value": [ "Pre-Text", "Post-text." ] }, "param": "value" } } |