![]() query-json allows you to write small programs to operate on top of json files with a concise syntax. Enter your JSON/XML and your query and immediately see the extracted results in the browser. Basic usageĬonsider the following JSON document named doc. query-json is a faster, simpler and more portable implementation of the jq language in Reason distributed as a dependency-free binary thanks to the OCaml compiler, and distributed to the web with jsofocaml. Online tool for querying, extracting or selecting parts of a JSON or XML document or testing a query using JSONPath, JSPath, Lodash, Underscore, JPath, XPath for JSON, JSON Pointer, XPath, XSLT or just plain old JavaScript. | query or function or field Ī filter containing only a path will filter the JSON data and output only the fields corresponding to it.Īdding a pipe in the filter indicates a multi-stage operation, where the output from the previous stage will be passed unto the next stage for further filtering/transformation. The filter follows the any of the following syntaxes: ![]() The filter specifies how the JSON input will be outputted in the console (or file if you use > or > in any shell). How does it workĪ JSON document/dataset is taken as input and is passed to a specified filter, and the output is passed through the pipe(s), eventually outputted unto the console. Unfortunately, shells such as Bash can’t interpret and work with JSON directly. ![]() If the key contains special characters, you need to surround it with double quotes like this. When given a JSON object (aka dictionary or hash) as input, it produces the value at the key foo, or null if there’s none present. It’s particularly popular in web applications due to its lightweight nature and compatibility with JavaScript. The jq Manual (development) -> Basic filters. Installation is simply a matter of either downloading the binary from the website ( ), or via yum/apt-get/dnf installation commands if you are using Linux. JSON is a widely employed structured data format typically used in most modern APIs and data services. Use the -yaml-output / -y option to convert it back into YAML: cat input.yml yq -y. foo.bar input.yml By default, no conversion of jq output is done. foo.bar Like in jq, you can also specify input filename (s) as arguments: yq. Be it for periodically checking a JSON API, or interpreting JSON data.īefore you bust out your grepping chops to parse whatever you need on the JSON output, you may want to check out jq.Īs mentioned in its website ( ), jq is like sed for JSON data, you can query it, filter it according to your needs, and event generate a new JSON document or dataset based on the output. yq takes YAML input, converts it to JSON, and pipes it to jq: cat input.yml yq. Somewhere down your DevOps journey, you may encounter a need for handling JSON data using bash as part of your automation needs.
0 Comments
Leave a Reply. |