jq
टेक्स्ट प्रोसेसिंग
इस्तेमाल
jq '[filter]' [file.json]JSON को अपनी छोटी भाषा से छानकर नया आकार देता है; यह अक्सर पहले से स्थापित नहीं होता, और strings के quote हटाने के लिए -r चाहिए।
आम विकल्प
| विकल्प | अर्थ |
|---|---|
| -r | Raw output, so strings come out without quotes |
| -c | One compact line per result |
| -e | Set the exit status from the result, for scripts |
| --arg | Pass a shell string in as a jq variable |
| -s | Slurp the whole input into one array |
| -n | Start from null input and build output yourself |
उदाहरण
curl -s api/users | jq -r '.[].name'Every name, unquoted, one per line.
jq '.items | length' data.jsonCounts the entries in an array.
jq -c '.[] | {id, name}' big.jsonTwo fields per row, compact.
ये पाइप से जोड़कर चलाने के लिए बने हैं। एक ही कमांड से सब करवाने के बजाय तीन जोड़ना छोटा पड़ता है।
कैसे पढ़ें
- बड़े कोष्ठक [ ] उस हिस्से को दिखाते हैं जिसे छोड़ा जा सकता है।
- तीन बिंदु … का मतलब है एक से ज़्यादा दिए जा सकते हैं।
- विकल्पों में बड़े-छोटे अक्षर मायने रखते हैं — कुछ कमांड में -r और -R अलग काम करते हैं।
आम सवाल
Q. jq क्या करता है?
JSON को अपनी छोटी भाषा से छानकर नया आकार देता है; यह अक्सर पहले से स्थापित नहीं होता, और strings के quote हटाने के लिए -r चाहिए।
Q. इसे कैसे लिखें?
jq '[filter]' [file.json] — बड़े कोष्ठक वह हिस्सा दिखाते हैं जो छोड़ा जा सकता है।
Q. कितने विकल्प जानने लायक़ हैं?
यहाँ 6 दिए हैं; पूरी सूची man jq में है। यह कमांड टेक्स्ट प्रोसेसिंग में आती है।
मिलती-जुलती कमांड
man पेज: man jq