Formatting JSON for readability

Charly's Column – JSON

Article from Issue 238/2020
Author(s):

Armed with just json.tool and jq, Charly preps the JSON data delivered by his Philips Hue bridge so that even humans can read it – an essential step towards improving the usability of his home automation system.

Some time ago [1], I briefly talked about how I use the measured values from a lux sensor to control a Hue lighting system. In redecorating my hallway, I added some new lights and removed others. I couldn't remember the light sources' IDs, so I asked the Hue bridge to dump the configuration. What I got was hard-core JSON, but unfortunately not in a human-readable format (Figure 1).

Figure 1: Unreadable: Pure JSON.

There are plenty of tools to make JSON readable. I started with what I already had in place, json.tool, which the Python installation had dumped on my hard disk. I wrote its neatly formatted output to a file in /tmp for further processing (Listing 1).

[...]

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • JSON Deep Dive

    JSON data format is a standard feature of today's Internet – and a common option for mobile and desktop apps – but many users still regard it as something of a mystery. We'll take a close look at JSON format and some of the free tools you can use for reading and manipulating JSON data.

  • Enlightened libcoap

    Charly did a spot of shopping in a furniture store and came out with a smart lighting system that he has now automated with a Linux PC: Read on for further enlightenment.

  • Hue and Rasp Pi

    Since his Trådfri Smarthome article over a year ago, sys admin columnist Charly has been receiving messages from readers with two questions: "Can you do that with the Philips' Hue system?" and "Can this also be done with a normal brightness sensor?" Yes and yes!

  • The sys admin's daily grind: colorls

    The first time in our lives we got to a black-and-white Linux or Unix shell, most of us probably typed ls first. In a mixture of nostalgia and the knowledge that life is colorful, columnist Charly Kühnast plays a colorful trump card with colorls.

  • Two Types of Round Trip

    Due to the COVID-19 lockdown, Charly has time to devote to gadgets like graphical ping tools, flashing space stations, and space walks.

comments powered by Disqus