Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I will get one out put from this string @json1

{                
   "Status": "Success",                
   "Status Message": "Service Call Successful",                
   "Area":                
   [                
    
    {                
     "AreaCode":"A00009",                
     "AreaName":"BARSHI",                
     "FsCode":"TSM010",               
     "RegionCode":"R00001",                
     "RegionName":"MAHARASHTRA"                
   }, 
   {                
     "AreaCode":"A00008",                
     "AreaName":"BANGALORE",                
     "FsCode":"TSM040",               
     "RegionCode":"R00901",                
     "RegionName":"KARNATAKA"                
   },                              
    ]                
        }

now i want to replace last charecter ',' between '}' and ']' symbol any solution would be greatly appreciated..

What I have tried:

i have tried
SQL
set @json1=reverse(STUFF(REVERSE(@json1),charindex(',',@json1),1,''))


but no use..
i want out put like this

{                
   "Status": "Success",                
   "Status Message": "Service Call Successful",                
   "Area":                
[                
    
    {                
     "AreaCode":"A00009",                
     "AreaName":"BARSHI",                
     "FsCode":"TSM010",               
     "RegionCode":"R00001",                
     "RegionName":"MAHARASHTRA"                
   }, 
   {                
     "AreaCode":"A00008",                
     "AreaName":"BANGALORE",                
     "FsCode":"TSM040",               
     "RegionCode":"R00901",                
     "RegionName":"KARNATAKA"                
   }                              
   ]                
}
Posted
Updated 25-Feb-16 6:57am
v2
Comments
dan!sh 25-Feb-16 1:06am    
Take a look at this question on CodeProject: Here
CHill60 25-Feb-16 12:12pm    
What has this got to do with rownumber?

1 solution

Here's the solution (accordingly):

SET @json1 = REVERSE(STUFF(REVERSE(@json1),CHARINDEX(',',REVERSE(@json1)),1,''))

You almost had it right.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900