Home > Web Front-end > JS Tutorial > body text

Sharing of JSON-friendly printing techniques using jq under Linux_javascript techniques

WBOY
Release: 2016-05-16 16:30:57
Original
2566 people have browsed it

When I printed JSON on the command line before, it was always Cat, and then I copied the result to an editor that supports JSON parsing, which was very tortuous.

After a simple search, I found an article on StackOverflow. The answer with the highest support rate requires the support of Python2.6, but the version on the server is 2.4. The impact of the upgrade is unpredictable, so I gave up.

Continue to read the answers below. There is a small tool called jq that seems to be pretty good. Download it and test it and it can indeed meet the requirements.

#cat food.json | jq '.'
You can get the formatted results

Let me introduce jq to you in detail

jq official website: http://stedolan.github.io/jq/

After downloading the binary, you can call it directly. For detailed installation, please see: http://stedolan.github.io/jq/download/

Easy to use:
1. Friendly display of json files

Copy code The code is as follows:

cat jsonfile | path_to_jq/jq .

2. Get the value of a certain key in json
Copy code The code is as follows:

cat jsonfile | path_to_jq/jq ".key"

For more operations, see: http://stedolan.github.io/jq/manual/

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template