Payments are experiencing issues due to temporary restrictions in Russia. If your payment does not go through, please submit a support request.Our support team is available 24/7 — we are always here to help with hosting and server issues.We are now accepting requests for dedicated server rental and colocation services in our data center.Reminder: we recommend enabling backups for additional data protection.A new VPS/VDS lineup with NVMe storage and improved performance is now available.Maintenance work on some servers has been completed. All services are operating normally.
Article4 min readViews0

How to Validate a JSON File with jq Before Importing to a Store

Check syntax, empty files, multiple documents in sequence, and the top-level type. Read commands with verified examples for jq 1.7.

Comments 0

Two transparent plates with different openings: separate checks for JSON syntax and the contract
In this article

The exchange file was saved, but the import rejected it. Before retrying, it is useful to check the file itself: does it contain JSON, is it exactly one document, and does the receiver expect that data type? Successful syntax parsing answers only the first of these questions.

This guide is intended for Linux, the Bash shell, and an already installed jq version 1.7. Checks were performed on September 27, 2026, in an isolated Linux environment with jq-1.7 on small test files. Commands read a local copy; store settings, services, and data remain unchanged. Standard file read permissions are required; administrative privileges are not needed.

Prepare a small anonymized file

Work with an authorized copy that contains no passwords or customer data. In the examples, ./payload.json represents the path to your local file in the current directory. Replace it with the required path; enclose names with spaces in quotes. Do not redirect output back to the source file: overwriting is unnecessary for diagnostics.

First, confirm the utility version:

jq --version

If the program is missing, stop and arrange its installation separately. An error accessing the file does not indicate JSON corruption. It means the content check has not yet occurred. Do not send a full working package to a random online validator.

Verify that jq can read the content

jq empty ./payload.json

The empty filter does not print parsed values. Therefore, a valid file typically produces empty output. Immediately after the command, read the exit code:

echo $?

This is the code from the previous Bash command. Do not run other commands between the check and reading it. A zero value means the filter executed successfully. A non-zero code must be analyzed together with the error message: the cause can be syntax errors, an inaccessible file, or incorrect execution.

In the sample file with a missing value after the colon, the utility reported a parsing error and indicated the line and column. This is the location of detection, not necessarily the location of the original error: for example, an unclosed quote might have appeared earlier. Do not guess-fix a working export; pass an anonymized fragment to the person generating the package.

Empty output does not mean a single document

On the test stand, an empty file also passed jq empty with a zero code. A sequence of two objects, {} and {}, also passed: the utility can read a stream of individual JSON values. However, your import method may require exactly one object. For that case, both types of files are unsuitable.

If the contract requires a single top-level JSON object, use a separate check:

jq -e -s 'length == 1 and (.[0] | type == "object")' ./payload.json

The -s parameter collects the read values into an array. The condition checks that there is a single value and that it is an object. The -e parameter allows using the result of the condition as an exit code. In our examples, one object yielded true and exit code zero; an empty file, two objects, an array, and null yielded false and exit code one. A corrupted JSON file ended with a parse error.

The purpose of the check is important here. If the API contract accepts an array of orders, rejecting an array with this filter is the expected result of an incorrectly chosen condition. Do not turn a requirement for one specific method into a rule for all JSON files.

The -s mode has a cost: it loads the entire input into memory. These commands have been tested on small files. Do not run such a check on a multi-gigabyte export from a loaded server; for large streams, you need a separately designed parser with resource limits. A small example does not confirm that a large package can handle the load.

What remains outside this check

An object may successfully pass both checks and still contain invalid fields, an unknown identifier, or a negative quantity. Syntax parsing and top-level validation do not confirm the schema, order modification permissions, or the validity of the business operation.

Pay separate attention to duplicate property names. The JSON standard recommends unique names; programs may handle duplicates differently. Do not treat a standard successful parse as confirmation of their absence. If the contract forbids duplicates, a mechanism is needed to detect them before information is lost during conversion to an object.

To contact the developer, preserve the jq version, the exact command, the exit code, and an anonymized message. Add a recipient rule: one object, array, or consistent stream. This turns the statement "file does not import" into a verifiable result: syntax is readable, but the document count or top-level type does not match the contract. Once this boundary is resolved, proceed to field validation and test import.

Discussion 0

Share your experience and ask questions. Comments without links appear after editorial review.

No comments yet. Start the discussion.