As a simplified example, consider this table with two fields. One is a string and the other is XML.
SELECT TOP (1) [Source]
, OrderParameter
FROM [Rops].[dbo].[PreOrder]
- Source="MediaConversions"
- OrderParameter="<?xml version="1.0" encoding="utf-16"?>"
Now I want to query the table and have the results as json, but also have the XML converted as json in one go.
SELECT TOP (1) [Source]
, OrderParameter
FROM [Rops].[dbo].[PreOrder]
for json path;
results in
[{"Source":"MediaConversions","OrderParameter":"<ParameterList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />"}]
But I want it to be converted into:
[{"Source":"MediaConversions","OrderParameter":{ "ParameterList": [ "x": 1, "y": 10] } ]
How to add "for json" to have the xml converted?
SELECT TOP (1) [Source]
, select OrderParameter for json path????
FROM [Rops].[dbo].[PreOrder]
for json path;
<ParameterList ...
etc., when the entered data forOrderParameter
is<?xml version="1.0" encoding="utf-16"?>
. I created a temp table in MS SQL Server and ran your second query (the one that ends infor json path
), which gave me[{"Source":"MediaConversions","OrderParameter":"<?xml version=\"1.0\" encoding=\"utf-16\"?>"}]
. I'm not sure I see the problem. – RobJarvis