4

How can I get GeoServer WMS GetCapabilities request as JSON?

For example this is a WMS link: https://www.ngs.noaa.gov/GeoServer/NSDE/ows?service=WMS&request=GetCapabilities&

I am getting this request via AJAX call. But response is XML formatted like this:

<Format>text/xml</Format>

<GetCapabilities>
<Format>text/xml</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xlink:type="simple" xlink:href="http://www.ngs.noaa.gov:80/GeoServer/NSDE/ows?SERVICE=WMS&"/>
</Get>
<Post>
<OnlineResource xlink:type="simple" xlink:href="http://www.ngs.noaa.gov:80/GeoServer/NSDE/ows?SERVICE=WMS&"/>
</Post>
</HTTP>
</DCPType>
</GetCapabilities>

I want to get this response as JSON format. Can I change format settings from GeoServer?

  • Not sure if a duplicate, but related: gis.stackexchange.com/questions/34892/… – pLumo Jul 27 '17 at 10:31
  • @RoVo, this isn't a duplicate of the WFS GetFeature as JSON question you link to. A WFS GetFeature can output in multiple formats including JSON (as long as it has been enabled on the server). The questions are also asked from two points of view, this question comes from a consumer of a web service, the other from a publisher of a web service able to configure which formats the server offers. – nmtoken Jul 27 '17 at 14:06
  • Thanks for clarification. Like I said I was not sure. – pLumo Jul 27 '17 at 14:10
2

It's not possible to get the WMS GetCapabilities response as JSON, only XML is supported, this is what this GeoServer GetCapabilities response is telling you and this is what you are stuck with.

If I remember correctly this is actually specified in the WMS specification, other WMS operations allow a format to be specified, but not the GetCapabilities request.

  • At GeoServer documentation page (docs.geoserver.org/stable/en/user/services/wms/reference.html) there is a format option as a vendor specific paramater. It is explained as "format request the capabilities document in a certain format". Unfortunately I couldn't test it. Do you have any information about that parameter? – senol ozgur Jul 27 '17 at 7:29
  • Not sure if I reading the same bit as you, but format_options, is not about specifying a new format for an operation – nmtoken Jul 27 '17 at 7:37
  • It's at that part: GeoServer provides the following vendor-specific parameters for the GetCapabilities operation. They are fully documented in the WMS vendor parameters section. ... format No request the capabilities document in a certain format – senol ozgur Jul 27 '17 at 7:39
  • OK, it says that the The response is a Capabilities XML document, so though there is a vendor option to specify a format, the only option would be XML; is how I read it. – nmtoken Jul 27 '17 at 13:56
0

GeoServer does not respond in JSON, but you can parse the XML to JSON yourself in your script. There are ready-made solutions:

As you mentioned AJAX I assume you're using JavaScript:

https://github.com/abdmob/x2js

In Python:

https://github.com/martinblech/xmltodict

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.