Jq (programming language)
jq is a very high-level lexically scoped functional programming language in which every JavaScript Object Notation (JSON) value is a constant. jq supports backtracking and managing indefinitely long streams of JSON data. It is related to two programming languages Icon and Haskell. The language supports a namespace-based module system and has some support for closures. functions and functional expressions can be used as parameters of other functions. The original implementation of jq was in Haskell[3] before being quickly ported to C. Historyjq was created by Stephen Dolan, and released in October 2012.[4][5] It was described as being "like sed for JSON data".[6] Support for regular expressions was added in jq version 1.5. A "wrapper" program for jq named yq adds support for YAML, XML and TOML. It was first released in 2017.[7] The Go implementation, gojq, was initially released in 2019.[8] gojq notably extends jq to include support for YAML. The Rust implementation, jaq, has as its project goals a faster and more correct implementation of jq, while preserving compatibility with jq in most cases. Explicitly excluded from the project goals as of March 2024 are certain advanced features of jq such as modules, SQL-style operators, and a streaming parser for very large JSON documents.[9] The jq implementation, jqjq, was initially released in 2022. jqjq notably can run itself, has a REPL and supports eval. UsageCommand-line usagejq is typically used at the command line and can be used with other command-line utilities, such as curl. Here is an example showing how the output of a $ curl -s 'https://en.wikipedia.org/w/api.php?action=parse&page=jq_(programming_language)&format=json' | jq '.parse.categories[]."*"'
The output produced by this pipeline consists of a stream of JSON strings, the first few of which are: "Articles_with_short_description"
"Short_description_matches_Wikidata"
"Dynamically_typed_programming_languages"
"Functional_languages"
"Programming_languages"
"Programming_languages_created_in_2012"
"Query_languages"
"2012_software"
The The jq filter shown is an abbreviation for the jq pipeline: .["parse"] | .["categories"] | .[] | .["*"]
This corresponds to the nested JSON structure produced by the call to Embedded usageBoth the C and the Go implementations provide libraries so that jq functions can be embedded in other applications and programming environments. For example, gojq has been integrated with SQLite so that a Modes of operationjq by default acts as a "stream editor" for JSON inputs, much like the sed utility can be thought of as a "stream editor" for lines of text. However jq has several other modes of operation:
The streaming parser is very useful when one of more of the JSON inputs is too large to fit in memory, since its memory needs are usually quite small. For example, for an arbitrarily large array of JSON objects, the peak memory need is little more than needed to handle the largest top-level object. These modes of operation can, within certain limitations, be combined. Syntax and semanticsTypesEvery JSON value is also a value in jq, which accordingly has the data types shown in the table below.[13] The gojq and jaq implementations distinguish between integers and non-integer numbers. The gojq implementation supports unbounded-precision integer arithmetic, as did the original implementation of jq in Haskell.
FormsSpecial syntactic forms exist for function creation, conditionals, stream reduction, and the module system. FiltersHere is an example of defining a named, parameterized filter for formatting an integer in any base from 2 to 36 inclusive. The implementation illustrates tacit (or point-free) programming: # Use gojq for infinite precision integer arithmetic
def tobase($b):
def digit: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[.:.+1];
def mod: . % $b;
def div: ((. - mod) / $b);
def digits: recurse( select(. >= $b) | div) | mod ;
select(2 <= $b and $b <= 36)
| [digits | digit] | reverse | add;
The next example demonstrates the use of generators in the classic "SEND MORE MONEY" verbal arithmetic game: def send_more_money:
def choose(m;n;used): ([range(m;n+1)] - used)[];
def num(a;b;c;d): 1000*a + 100*b + 10*c + d;
def num(a;b;c;d;e): 10*num(a;b;c;d) + e;
first(
1 as $m
| 0 as $o
| choose(8;9;[]) as $s
| choose(2;9;[$s]) as $e
| choose(2;9;[$s,$e]) as $n
| choose(2;9;[$s,$e,$n]) as $d
| choose(2;9;[$s,$e,$n,$d]) as $r
| choose(2;9;[$s,$e,$n,$d,$r]) as $y
| select(num($s;$e;$n;$d) + num($m;$o;$r;$e) ==
num($m;$o;$n;$e;$y))
| [$s,$e,$n,$d,$m,$o,$r,$e,$m,$o,$n,$e,$y] );
Parsing expression grammarsThere is a very close relationship between jq and the parsing expression grammar (PEG) formalism. [14] The relationship stems from the equivalence of the seven basic PEG operations and the jq constructs shown in the following table.
Ports and variantsgojq is a pure Go implementation. There is also a Rust implementation of a dialect of jq named jaq[9] for which a denotational semantics has been specified.[15] Notes
ReferencesBibliography
Others
External links
|
Portal di Ensiklopedia Dunia