JSON response via NAV

#This article will work with NAV 2016!

To get a JSON Response via NAV we can create a webservice-codeunit and publish it. Following this we probably use SOAP to publish the functions and will get a XML-response. In some projects it is easier to handle a JSON response. As well there are opportunities to read out a NAV response with the JSON format. The easiest way to do this is by publishing a page. To do this just go to the table “Web Service” (2000000076) and create an entry for a page. If you run this via the normal user-client (search for “web service”) you will see a Odata-link. This link is generated automatic. If you set on the Odata on the service tier and use this link you will get a response with the data of the page.

Probably it is xml-format but you can add the following at the end of you Odata-url:


Now your response should use the JSON-format.

If you want to do the same with a codeunit you will get no odata-link.  This is because we use a REST-service. A REST-service is done to have the basic-handler GET, POST, PUT, … . So if you would try to write some codeunit that should provide a json-response, the codeunit had to handle all of this basic-statements. A codeunit in NAV is not made to provide data like a real REST-service. But if you want to use data that way -> publish the data with a page and you can work with this.