'Why I am getting array JSON response when I call method from Web API?

I am getting array which include my JSON when I call that method in postman like

 [
    {
        "spark_version": "7.6.x-scala2.12"
    }
]

API Method

[HttpGet]
    public IActionResult GetTest(int ActivityId)
    {
        string StoredJson = "exec sp_GetJobJSONTest " +
            "@ActivityId = " + ActivityId ;
        var result =  _context.Test.FromSqlRaw(StoredJson);
        return Ok(result);
    }

I want to get rid from square brackets [ ] in my response. How should I do that ?



Solution 1:[1]

for getting first row need to use .FirstOrDefault()

[HttpGet]
    public IActionResult GetTest(int ActivityId)
    {
        string StoredJson = "exec sp_GetJobJSONTest " +
            "@ActivityId = " + ActivityId ;
        var result =  _context.Test.FromSqlRaw(StoredJson).ToList().FirstOrDefault();
        return Ok(new {details = result };);
    }
 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1