How to Read JSON?

Reading JSON can often seem daunting in programming. Parsing and formatting it in a way that is easy for humans to understand isn’t always straightforward. However, there are several ways to read JSON without the need for internet access.

Using jq

How to read JSON using jq

jq is a powerful command-line JSON processor that is perfect for parsing and formatting JSON. It allows you to extract specific fields from a JSON string.

jq '.' file.json

If the JSON content is already in your clipboard, you can use the following commands:

On Linux

# X11
xclip -o | jq

# Wayland
wl-paste | jq

On MacOS

pbpaste | jq

Using an IDE

Reading JSON within an IDE might initially seem challenging, as it often requires creating a new file to paste the JSON and format it. However, this approach can result in unnecessary files being created in your system. Fortunately, most IDEs support the concept of buffers, which allows you to read and edit JSON without creating new files.

Let’s take Visual Studio Code (VSCode) as an example:

How to read JSON in VSCode

Contributing

This guide was written by Chekoy and is licensed under MIT license. Send merge request on Gitlab.