1

Im making the api for showing the user info, so I write the code like this

res.json({"Status" : true , "User" : rows });

then i get the result

    {
      "Status": true,
      "User": [
        {
          "userid": 821786,
          "fullname": "undefined",
        }
      ]
    }

But I want the result like this

    {
      "Status": true,
      "userid": 821786,
      "fullname": "undefined"
    }

How can I do this ?

I tried

res.json({"Status" : true ,"Type":"Google",  rows });

but it gives me

    {
      "Status": true,
      "rows": [
        {
          "userid": 821786,
          "fullname": "undefined",
        }
      ]
    }

I can sure that only one result will be queried so i dont want to use array

1
  • Prepare code for response before putting it into res.json method Commented Feb 26, 2016 at 9:25

1 Answer 1

3

Try this:

var result = rows[0];
result.Status = true;
res.json(result);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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