How to create nested Jsons in teradata

General
Enthusiast

How to create nested Jsons in teradata

Hi, 

 

Data is in below format -

{a:123,b:456,a:789,b:283,a:384,b:485..etc}

 

We need like below format -

{{a:123,b:456},{a:789,b:283},{a:384,b:485}}

 

Could you please help me how to do this in teradata.

Thank you!

2 REPLIES 2
Ambassador

Re: How to create nested Jsons in teradata

You can apply a RegEx to find those patterns and add parens, e.g. if a & b are known:

RegExp_Replace(col, '(a:.+?,b:[^,}]+)', '{\1}', 1, 0, 'i')

or a more generic two group each two name-value-pairs:

RegExp_Replace(col, '([^{,}]+,[^,}]+)', '{\1}', 1, 0, 'i')

 

 

Enthusiast

Re: How to create nested Jsons in teradata

Thanks a lot, Dnoeth