Json_To_Xml

Converts a JSON string to XML

  • Free Function
  • SQL Server Compatibility: 2008, 2012, 2014, 2016, 2017

Syntax:

SELECT SQLHTTP.net.Json_To_Xml ( @Json, @NodeStyle )

Arguments:

Name Type Description
@Json nvarchar(MAX) Json string
@NodeStyle tinyint

One of these three values. See examples below.

  1. Simple conversion of the JSON Objects, Arrays, etc. using names and types as XML nodes and attributes. Very readable, but not reversible back to the original JSON.
  2. Uses the Json’s Objects, Arrays, etc. names, when available, as the newly created XML’s node names. Reversible back to the original JSON.
  3. Uses the Json’s types as the newly created XML’s node names. Reversible back to the original JSON

Return Type:

xml

Remarks:

The JsonDefaultNoNameNode field in the Defaults table can be updated to assign a different default node name for Json objects or arrays that are not named. Default value: NoName

Sample Usage:

The following JSON string is used for the examples below:
Using @NodeStyle = 0:
Using @NodeStyle = 1:

Using @NodeStyle = 2:

See Also: