4

I have a Json string. I Want to get value from that Json string.

This is my json string {"latitude":"22.5712854"},{"longitude":"88.4266847"}

I want only latitude and longitude from this, using TSQL query.

4
  • 3
    This could help you: simple-talk.com/sql/t-sql-programming/… Commented Jun 4, 2013 at 10:12
  • TSQL can't parse JSON natively and it's a very weak language for text parsing and handling in general (although you could parse the string you've shown using only SUBSTRING and CHARINDEX). It will almost certainly be easier to do this using code outside the database or possibly a CLR procedure; that way you can use a language that has JSON support or at least good text processing functions. Commented Jun 4, 2013 at 15:48
  • 2
    possible duplicate of Parse JSON in TSQL Commented Jun 4, 2013 at 23:40
  • Check the question duplicated here as flagged by AndrewC. Its answers are more thorough and it mentions the native JSON support in SQL Server 2016. Commented Feb 26, 2016 at 12:30

2 Answers 2

5

There is no native way to parse JSON in TSQL. But Phil Factor created his own implementation of paring JSON in SQL function. More about it on simple talk blog in article: Consuming JSON Strings in SQL Server

Aslo Ric Vander Ark created his own function but I did not tested it. You can read more on article: A Function to Split JSON Data

Sign up to request clarification or add additional context in comments.

2 Comments

"There is no native way to parse JSON in TSQL. But Phil Factor created his own implementation [to parse JSON in TSQL]" <-- Contradiction at its best. Still, thanks for the link on how to parse JSON in TSQL. :)
A custom implementation, as listed is different to a native (i.e. built in) way.
0

You could use JSON Select which has several functions for extracting different datatypes from JSON. For your requirements you could do something like this:

select 
    dbo.JsonDecimal(my_column, 'latitude') as latitude,
    dbo.JsonDecimal(my_column, 'longitude') as longitude
from my_table

DISCLOSURE: I am the author of JSON Select, and as such have an interest in you using it :)

1 Comment

Hi @joshuahealy, Could you please provide documentation of JsonSelect as the site is not online right now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.