How to view the data from the database in json format - json

I am trying to pass the data from the database to the controller through a service (WCF Data Service), which is an independent application. While running the service for testing, the data is shown in XML format. I need to view the data in JSON format. Any solutions??
Thanks in Advance

For JSON support:
Download the JSONPSupportBehavior.cs from the Microsoft Code Gallery
Locate the JSONPSupportBehavior.cs file in the downloaded project and include it in your web project.
Add a reference to System.Runtime.Serialization.dll.
Mark your service with the JSONPSupportBehavior attribute.
[JSONPSupportBehavior]
public class WcfDataService : DataService<SampleDbEntities>
Please refer this link
A Beginner's Tutorial for Creating WCF Data Services
Hope this helps

WCF Data services supports JSON out of the box.
In order to receive a response in JSON format, you can include application/json in the accept header of the request. Or you can use $format=json in your request url.

Related

Does Tibco WebFOCUS only return XML Response for REST calls?

I am new to Tibco WebFocus. I want to connect to my Webfocus environment from Java code. I am going through one of the pdf document given by webfocus which is a developer guide for communication between webfocus and rest application. So in that document I see only XML response but no JSON response for a Rest call and the version of webfocus mentioned in the document is 82.07. I want to know if we can get the JSON response from Webfocus as it will be convenient and lightweight for Java.
Thanks in advance.

How to specify JSON parameters in a WADL file?

Dear StackOverflow Experts,
We have a requirement to access an API from SAP BODS. SAP BODS needs a WADL file configured in order to access the API. The API we are trying to call is a rest services API with a POST method and accepts only JSON parameters as input.
I have tried using SOAP UI to generate the WADL file but the WADL file does not include the JSON input parameters in the file.
Can anyone help me with a sample code of how a JSON input can be specified as a parameter in the WADL file.
I have tried going through all the documentation that is available but could not come across anything that could help.
I am new to API and any help is appreciated.

How to create web service to receive JSON?

I am new to web services. I need to create a web service that will receive JSON from a source in VB.NET. Could you please help on how to start with this?
Earlier I have called web service and received JSON from it after getting the HTTPResponse. But in this case, source will send the data and my web service need to receive it. Thank you for your help.
After some google I was able to understand the WCF concept. All I did was create a contract with attributes as:
<OperationContract>
<WebInvoke(Method:="POST",
ResponseFormat:=WebMessageFormat.Json,
RequestFormat:=WebMessageFormat.Json,
BodyStyle:=WebMessageBodyStyle.Bare,
UriTemplate:="InputData")>
for my method.
Then I added endpoint and binding as "webHttpBinding".
Created classes to deserialize JSON and I was good to go.

ASP.Net MVC WEB API - JSON - auto add API version to generated JSON

I have developed an ASP.NET WEB API that generates JSON data to be consumed by some other party. Now I have received a request for adding some extra data in each JSON response about the version of the WEB API.
Is there a simple way to extend the built-in JSON formatter so it will auto-append/prepend some fixed JSON properties whenever it formats some data-model or a collection of some data-model?
Thanks for any good advice :-)

Save a JSON image in a server

I'm writing a RESTful web application where I need to provide the service of uploading images for a user. Currently, I have been able to upload an image from my current machine but I need to send it as JSON data over the web through the REST protocol.
In the server, there is a Java application running Jax-RS to manage the RESTful service. I was planning to save the JSON data that contains the image in the server and then provide a URL to the user for him to be able to locate it's image on the server.
Can someone provide some ideas on how can I do this?
If you want to send the image in a JSON object, then the image should be Base64 encoded it, or some other form of encoding. Then on the server side you will need to unmarshal the JSON and then decode back the image. You can get some ideas here on how that can be done.
Optionally, instead of doing all the converting inside the resource method (as in the example linked above), you could write a custom MessageBodyReader, where you can do the unmarshalling and decoding there.
If you decide you don't want to work with JSON, you can go the normal route and use Multipart. Depending on the implementation of JAX-RS you are using, multipart support will be different. You can see some examples (all examples have links to the official documentation)
Jersey example
Resteasy example
CXF example
There are other implementations, but I don't have examples for those. You will need to search for the documentation if you're using an implementation other than listed above.