SQL Server
SQL Server
JSON PathPrefix Example
Demonstrates the JSON object'sPathPrefix property.
Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @json, 'PathPrefix', 'company.billing.'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'company_name', 'TechNova Solutions Inc.'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'address_line_1', '123 Innovation Drive'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'address_line_2', 'Suite 450'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'city', 'Seattle'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'state_province', 'WA'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'postal_code', '98101'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'country', 'USA'
EXEC sp_OASetProperty @json, 'EmitCompact', 0
EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT
PRINT @sTmp0
-- Result:
-- {
-- "company": {
-- "billing": {
-- "company_name": "TechNova Solutions Inc.",
-- "address_line_1": "123 Innovation Drive",
-- "address_line_2": "Suite 450",
-- "city": "Seattle",
-- "state_province": "WA",
-- "postal_code": "98101",
-- "country": "USA"
-- }
-- }
-- }
DECLARE @city nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @city OUT, 'city'
PRINT 'city = ' + @city
EXEC @hr = sp_OADestroy @json
END
GO