如何使用OpenJson将JSON列标头转换为小写



我试图在SQL Server中解析JSON数据。列标头是混合大小写。有办法把它转换成大写或小写吗?下面是代码:

SELECT  
pr.AuditEvent_Id as [AuditEvent_HttpHeaders_Id]
,[AuditEvent_HttpHeaders_ContentType]
,[AuditEvent_HttpHeaders_Accept]
,[AuditEvent_HttpHeaders_AcceptEncoding]
,[AuditEvent_HttpHeaders_AcceptLanguage]
,[AuditEvent_HttpHeaders_Authorization]
,[AuditEvent_HttpHeaders_Host]
,[AuditEvent_HttpHeaders_Referer]
,[AuditEvent_HttpHeaders_UserAgent]
,[AuditEvent_HttpHeaders_Origin]
FROM dbo.Audit_Resource pr
CROSS APPLY OpenJson(pr.HttpHeaders) WITH (
[AuditEvent_HttpHeaders_ContentType] varchar(255) '$."content-Type"',
[AuditEvent_HttpHeaders_Accept] varchar(255) '$.accept',
[AuditEvent_HttpHeaders_AcceptEncoding] varchar(255) '$."accept-Encoding"',
[AuditEvent_HttpHeaders_AcceptLanguage] varchar(255) '$."accept-Language"',
[AuditEvent_HttpHeaders_Authorization] varchar(255) '$.authorization',
[AuditEvent_HttpHeaders_Host] varchar(255) '$.host',
[AuditEvent_HttpHeaders_Referer] varchar(255) '$.referer',
[AuditEvent_HttpHeaders_UserAgent] varchar(255) '$."user-Agent"',
[AuditEvent_HttpHeaders_Origin] varchar(255) '$.origin',)

例如:在某些情况下,'$."content-Type"'就是'$."content-Type"'。如何使它不区分大小写。

SELECT  
pr.AuditEvent_Id as [AuditEvent_HttpHeaders_Id]
,[AuditEvent_HttpHeaders_ContentType]
,[AuditEvent_HttpHeaders_Accept]
,[AuditEvent_HttpHeaders_AcceptEncoding]
,[AuditEvent_HttpHeaders_AcceptLanguage]
,[AuditEvent_HttpHeaders_Authorization]
,[AuditEvent_HttpHeaders_Host]
,[AuditEvent_HttpHeaders_Referer]
,[AuditEvent_HttpHeaders_UserAgent]
,[AuditEvent_HttpHeaders_Origin]
FROM dbo.Audit_Resource pr
CROSS APPLY ( values ( replace(
replace(
replace(
replace(pr.HttpHeaders,'Content-Type','content-type')
,'Accept','accept')
,'accept-Encoding','accept-encoding')
,'accept-Language','accept-language')  -- ... Other Keys
) )J(S)
CROSS APPLY OpenJson(J.S) WITH (
[AuditEvent_HttpHeaders_ContentType] varchar(255) '$."content-Type"',
[AuditEvent_HttpHeaders_Accept] varchar(255) '$.accept',
[AuditEvent_HttpHeaders_AcceptEncoding] varchar(255) '$."accept-Encoding"',
[AuditEvent_HttpHeaders_AcceptLanguage] varchar(255) '$."accept-Language"',
[AuditEvent_HttpHeaders_Authorization] varchar(255) '$.authorization',
[AuditEvent_HttpHeaders_Host] varchar(255) '$.host',
[AuditEvent_HttpHeaders_Referer] varchar(255) '$.referer',
[AuditEvent_HttpHeaders_UserAgent] varchar(255) '$."user-Agent"',
[AuditEvent_HttpHeaders_Origin] varchar(255) '$.origin',)

相关内容

  • 没有找到相关文章

最新更新