Useful Commands & Tools When Working With JSON & REST API

Updated: 2018-07-29: Added a link to another online REST client and a JSON formatter to provide you with some additional options.


Original Post:

Over the years I have worked with JSON (JavaScript Object Notation) to create various automation and or orchestration workflows which integrate with system providing a Representational State Transfer (REST) Application Programming Interface (API). This post will summarise the tools I use on a regular basis. Some of the figures in this blog post show up with really small text so please click them to review their content.

  1. curl – which is a command line tool for transferring data. See cURL wiki page for additional information. The curl command is available by default on Mac OS which is have used for the past 7 years.
  2. Postman – This is an UI based tool that “Helps you develop APIs faster” according to the product information. Anyway, it’s really easy to use.
  3. Python – No I’m not a python programmer but I intend to learn it in the future since I think it’s time to move on from the bash scrips I create on a regular basis 🙂 I’m using python to format the JSON output in a terminal (I use iTerm on my Mac). Just compare the output form the two curl command examples below where the first one does not use python to format the output but the second one does. The only thing you need to add to your curl REST API command is “| python -m json.tool”
    This will make you appreciate the python magic quite a lot:)

    • Command “curl -k -u userXYZ -X GET –header ‘Accept: application/json’ ‘https://npx5.vcdx56.com:9440/PrismGateway/services/rest/v2.0/networks/’ gives the following output which is not that easy to read:
    • Command “curl -k -u userXYZ -X GET –header ‘Accept: application/json’ ‘https://npx5.vcdx56.com:9440/PrismGateway/services/rest/v2.0/networks/’ | python -m json.tool” gives the following output which is pretty easy to read, change and reuse:
  4. JSON Validator JSONLint – This online JSON formatter/editor has helped me multiple times over the years to make sure the JSON code is actually correct.
    1. Paste the code into the textbox and press “Validate JSON” button. You’ll get the result immediately and in this case it was a valid JSON format.
    2. This example shows an invalid JSON format and the tool actually highlights the line including the error and tells you what is wrong – Pretty nice:)
  5. Pretty Print JSON – If you don’t have the option of formatting the JSON output you receive from a command you can past the output in the Pretty Print JSON online tool.
    • Paste the JSON output and press “JSON Pretty Print” button
    • This is the output (very much like the output from the python option (1)

And yes I know there is a ton of useful tools out there but above are the once I use on a regular basis. Some other online tools are: