September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,22 @@
|
|||
# An empty object:
|
||||
{}
|
||||
|
||||
# Its type:
|
||||
{} | type
|
||||
# "object"
|
||||
|
||||
# An object literal:
|
||||
{"a": 97, "b" : 98}
|
||||
|
||||
# Programmatic object construction:
|
||||
reduce ("a", "b", "c", "d") as $c ({}; . + { ($c) : ($c|explode[.0])} )
|
||||
# {"a":97,"c":99,"b":98,"d":100}
|
||||
|
||||
# Same as above:
|
||||
reduce range (97;101) as $i ({}; . + { ([$i]|implode) : $i })
|
||||
|
||||
# Addition of a key/value pair by assignment:
|
||||
{}["A"] = 65 # in this case, the object being added to is {}
|
||||
|
||||
# Alteration of the value of an existing key:
|
||||
{"A": 65}["A"] = "AA"
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
def collisionless:
|
||||
if type == "object" then with_entries(.value = (.value|collisionless))|tostring
|
||||
elif type == "array" then map(collisionless)|tostring
|
||||
else (type[0:1] + tostring)
|
||||
end;
|
||||
|
||||
# WARNING: addKey(key;value) will erase any previous value associated with key
|
||||
def addKey(key;value):
|
||||
if type == "object" then . + { (key|collisionless): value }
|
||||
else {} | addKey(key;value)
|
||||
end;
|
||||
|
||||
def getKey(key): .[key|collisionless];
|
||||
|
||||
def removeKey(key): delpaths( [ [key|collisionless] ] );
|
||||
|
|
@ -0,0 +1 @@
|
|||
{} | addKey(1;"one") | addKey(2; "two") | removeKey(1) | getKey(2)
|
||||
|
|
@ -0,0 +1 @@
|
|||
"two"
|
||||
Loading…
Add table
Add a link
Reference in a new issue