/* Mango */
/* Pear */</lang>
=={{header|jq}}==
In practice, jq's arrays would probably be used whenever a singly-linked list might otherwise be used, but to illustrate traversal through a linked list, let us use JSON objects with keys "car" and "cdr", where a "cdr" value of null indicates the end of the linked list.
For example:
<lang jq>def test_list:
{ "car": 1, "cdr": { "car": 2, "cdr": { "car": 3, "cdr": null }}};
</lang>
To illustrate iteration along the links:
def traverse: .car, (.cdr | if . == null then empty else traverse end);
A more mind-bending approach is to use recurse/1:
def traverse2: recurse( .cdr ) | .car;
'''test_list | traverse''' and '''test_list | traverse2''' produce identical results: a stream of the "car" values.
=={{header|jq}}==
|