Binary inspection and JSON
Quick answer
Not every file is a line-oriented text document. Inspect unfamiliar binary files using byte-oriented tools, and use a JSON parser for structured JSON. Choose the tool based on the data format, not the filename extension alone.
Prepare the practice environment
Use the chapter fixture described in lab-fixtures/search-transform/README.md. Run setup as a normal user in a disposable Linux environment, enter the printed directory and check pwd. Every example assumes a fresh fixture. Commands omit the terminal prompt; outputs below are not commands.
How it works
GNU od -An -tx1 displays bytes as hexadecimal, with no offset column; -v disables repeated-line suppression. strings extracts printable sequences, not a complete decoding. hexdump and xxd are optional byte-viewing tools not installed in the tested environment. jq parses JSON; .name selects a field, .items[] iterates through an array, and -r prints string results without JSON quotes. A missing object field normally yields null. jq is a separate package; install only through a trusted distribution procedure if needed. Do not try to parse arbitrary JSON with grep or sed.
A hex dump shows the underlying bytes without asking the terminal to interpret them as text. JSON processing is a different task: a parser recognizes structured values, while a field selector chooses part of that structure. Valid JSON can still have missing fields or unexpected types. Check the expected schema before accepting extracted values in a report.
Try the examples
Hexadecimal pairs represent NUL, A, byte ff and LF.
Expected stdout:
00 41 ff 0aOnly the printable run of at least four characters appears; this is not a complete binary decoder.
Expected stdout:
HELLOThe filter iterates objects in items and extracts each name; -r removes JSON string quoting.
Expected stdout:
penbookCommon mistakes
Do not cat unknown binaries into a terminal or treat strings output as proof of file type. A valid JSON document is not necessarily a valid application schema.
Practice
Use jq to select .items[].qty and sum the two quantities with jq filter [.items[].qty] | add (quote the whole filter). Expected total: 5.
Related references
Study: strings, od, hexdump, xxd, jq. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Binary inspection and JSON — Knowledge Check
Apply the lesson concepts to the controlled text fixture.
Which tool is appropriate for arbitrary JSON fields?
What does od -tx1 display?
What does jq -r do to string results?
What does strings output prove?