node js sending json body in response

re-posting this question with different information.

I have 3 parameters.

  response.writeHead(200, 
        {       
         'Content-Type': 'text/json'            
        });      
      response.end({ID:'bufid',Name: bufname,address: bufaddrss});

    }

This is not working. Here I want to send to the end user in 200 Ok a JSON Body as:

{'ID; :'123',
  'Name': 'alice',
   'address': 'xxxxx'}

Here bufid,bufname and bufaddrss are values which are determined by functions and which can be accessible any where (they are global)

how can I send that information

First you have to realize that the following:

{ID:'bufid',Name: bufname,address: bufaddrss}

is not JSON. JSON is a protocol. It is a string that encodes a javascript object with a syntax that is similar to javascript object literal syntax (hence the confusion and mix-up most people have with the term "JSON").

You first need to convert that object to JSON formatted string. Fortunately node comes with a built in method: JSON.stringify().

response.end(
    JSON.stringify({ID: bufid,Name: bufname,address: bufaddrss})
);