What causes me to receive an array JSON response every time I make a call to a method in the Web API

When I call a method in Postman, I receive an array that includes my JSON data as shown below:

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

The 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 am looking for a way to remove the square brackets [ ] from my response. Any suggestions on how to accomplish this?

Answer №1

One way to retrieve the first row is by using .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 };);
    }
 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Make sure the "Treat labels as text" option is set to true when creating a chart in a Google spreadsheet using a script

I am currently working on a script using Google Spreadsheet Apps Script interface and I need to set the marker for 'Treat labels as text' to true. Despite searching through App Script documentation, I couldn't find any specific mention of t ...

Pattern matching to find occurrences of their, their's, theirs, theirs, and theirs' using regular expressions

I am attempting to create a regex in JavaScript that matches the different forms of "their" and its possessive form. Currently, I have their|their(?:'?s), which successfully matches their, theirs, and their's; but does not match theirs'. C ...

Facing an error response with the Javascript callout policy in Apigee. Any suggestions on fixing this issue?

This is the code snippet I'm using in my JavaScript callout policy var payload = JSON.parse(request.content); var headers = {'Content-Type' : 'application/json'}; var url = 'https://jsonplaceholder.typicode.com/posts'; va ...

Adding ngrx action class to reducer registration

Looking to transition my ngrx actions from createAction to a class-based approach, but encountering an error in the declaration of the action within the associated reducer: export enum ActionTypes { LOAD_PRODUCTS_FROM_API = '[Products] Load Products ...

Leveraging Angular2's observable stream in combination with *ngFor

Below is the code snippet I am working with: objs = [] getObjs() { let counter = 0 this.myService.getObjs() .map((obj) => { counter = counter > 5 ? 0 : counter; obj.col = counter; counter++; return view ...

Postman does not display the error, leading to a NodeJS server crash

Currently, I am in the process of implementing user authentication and establishing a protected route using JWT. I have developed an authMiddleware that is designed to throw an error if a token is missing. When I tested this functionality using Postman (wi ...

Getting the id of a row from a v-data-table in VueJs

I am currently facing an issue with retrieving the id of a specific field from each row. I require this id as a parameter for a function that will be utilized in an action button to delete the row. Here is how my table template appears: <template ...

Is it advisable to compress my API response in PHP?

At this stage, I find myself needing to generate extensive reports in order to gain a better understanding of the data at hand. To do so, I must retrieve one of my tables which contains around 50 parameters and 40,000 rows. While fetching the data via API ...

Twilio - encountering difficulties processing phone number upon submission

I clicked on this link to follow the tutorial (you can find it via twilio.) and after completing all the necessary steps, I encountered an issue. Upon running localhost and entering a phone number, I did not receive any text message and the verification wi ...

Guide on simulating an incoming http request (response) using cypress

Is there a way to mock a response for an HTTP request in Cypress? Let me demonstrate my current code: Cypress.Commands.add("FakeLoginWithMsal", (userId) => { cy.intercept('**/oauth2/v2.0/token', (req) => { ...

Manipulating input dates in AngularJSIn AngularJS, we can easily set the value

I'm having trouble setting a date field in my code. Despite trying to follow the example provided in the AngularJS documentation, nothing is showing up in the "departure" field. Here is what I have: HTML: <input type="date" name="departure" ng-mo ...

Enhancing the user experience of the dropdown component through improved

I have developed an accessibility feature for a dropdown component that dynamically populates values in the options menu only when the dropdown is opened. This means that it compiles the template on the fly and attaches it to the dropdown box. Dropdown HT ...

Displaying FontIcon in a NativeScript alert box

Would it be possible to display a fonticon on a Nativescript dialog? Similar to this example? dialogs.alert({ title: // set icon as text message: "Check-in Successful" }).then(()=> { console.log("Dialog closed!"); }); Is it feasible to ...

How can we prevent the continual overwriting of Object values?

I'm currently working on extracting data from the USDA Food Data Central API. Specifically, I'm interested in retrieving the "name" and "amount" values under the "nutrient" section. The excerpt below shows the information retrieved: Input- repor ...

I'm experiencing an issue where my express-session is being reset with every new request, leading me to question if this is related to the development environment I am using (REACT + EXPRESS)

UPDATE - I have ruled out a development environment issue as the same problem persists in production. Thank you for taking the time to look into this. I've searched through numerous questions and attempted various solutions with no success. To give ...

How to ensure jQuery runs only once, even when the back button is pressed in the

How can I ensure that jQuery only executes once, even when navigating back to the page using the browser's back button? When my page initially loads, the jQuery runs fine. However, if I navigate away from the page and then return using the back button ...

Exploring Facebook JSON data structures in PHP

Currently working on retrieving the user location data from Facebook. According to the User page on the Graph API, it mentions: location : A JSON object containing name and id I specifically require the location name, but I'm having trouble obtaini ...

Changing the depth buffer in a Three.js Shader Material

While working with Three js, I have implemented a vertex shader to animate a large geometry. Additionally, I have incorporated a Depth of Field effect into the output. However, I am encountering an issue where the Depth of Field effect does not seem to re ...

Toggle switch with active state

I'm currently using Ionic 2 alongside Angular 2 beta 11. Is there a way to turn off the toggle switch? The Ionic documentation suggests using the checked attribute, but I've tried that and also attempted ng-checked with no luck. Any advice on t ...

In C# Console, learn how to extract the first or first two digits from the string "12345-678" using the substring method

I'm currently working on a C# Console application where I need to replace hyphens with zeros to extend the length of a string from an identification card "123456-72." However, I'm encountering difficulties when it comes to sorting the array. My ...