0

My Json string has couple of items and I can use json_value to get specific items and parse it. But need to know the length of items to iterate.

[  
   {"name":"Ram", "email":"Ram@gmail.com"},  
   {"name":"David", "email":"David@gmail.com"},  
   {"name":"Bob", "email":"bob32@gmail.com"}  
]  

For example JSON_VALUE(@myJsonString, N'$[1].email') returns David@gmail.com but I need to know the length to increment.

Am I doomed to use openjson?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Aryan Firouzian
  • 1,940
  • 5
  • 27
  • 41
  • 1
    If `OPENJSON()` is not supported, probably a string-based approach is an option - `SELECT LEN(@json) - LEN(REPLACE(@json, N'{"name"', N'"name"'))` (the `@json` variable holds the input JSON). – Zhorov Aug 07 '20 at 09:05
  • yes, it worked for me even the final code seems a bit ugly. – Aryan Firouzian Aug 10 '20 at 09:00

0 Answers0