Skip to content

Instantly share code, notes, and snippets.

@Reino17
Created August 9, 2020 12:59
Show Gist options
  • Select an option

  • Save Reino17/5f5c22d36ebb6876c96808b97403c69c to your computer and use it in GitHub Desktop.

Select an option

Save Reino17/5f5c22d36ebb6876c96808b97403c69c to your computer and use it in GitHub Desktop.
'genesis.json':
{
"alloc": {
"0xca843569e3427144cead5e4d5999a3d0ccf92b8e": {
"balance": "1000000000000000000000000000"
},
"0x0fbdc686b912d7722dc86510934589e0aaf3b55a": {
"balance": "1000000000000000000000000000"
},
"0x9186eb3d20cbd1f5f992a950d808c4495153abd5": {
"balance": "1000000000000000000000000000"
},
"0x0638e1574728b6d862dd5d3a3e0942c3be47d996": {
"balance": "1000000000000000000000000000"
}
}
}
Directly:
$ xidel -s genesis.json -e '{"alloc":{|{"0x397559475c2d6cf48e10d33b1ab399ccb5f4546b":{"balance":"1000000000000000000000000000"}},$json/alloc|}}'
# JSONiq syntax, or...
$ xidel -s genesis.json -e '{"alloc":map:put($json/alloc,"0x397559475c2d6cf48e10d33b1ab399ccb5f4546b",{"balance":"1000000000000000000000000000"})}'
# a mix of JSONiq- and XQuery 3.1 syntax (available as from xidel-0.9.9.6739), or...
$ xidel -s genesis.json -e 'map{"alloc":map:put($json/alloc,"0x397559475c2d6cf48e10d33b1ab399ccb5f4546b",map{"balance":"1000000000000000000000000000"})}'
# XQuery 3.1 syntax (available as from xidel-0.9.9.6739) all produce the same output...
{
"alloc": {
"0x397559475c2d6cf48e10d33b1ab399ccb5f4546b": {
"balance": "1000000000000000000000000000"
},
"0xca843569e3427144cead5e4d5999a3d0ccf92b8e": {
"balance": "1000000000000000000000000000"
},
"0x0fbdc686b912d7722dc86510934589e0aaf3b55a": {
"balance": "1000000000000000000000000000"
},
"0x9186eb3d20cbd1f5f992a950d808c4495153abd5": {
"balance": "1000000000000000000000000000"
},
"0x0638e1574728b6d862dd5d3a3e0942c3be47d996": {
"balance": "1000000000000000000000000000"
}
}
}
------------------------------------------------------------------------------------------------
Variable:
$ var='0x397559475c2d6cf48e10d33b1ab399ccb5f4546b'
$ xidel -s genesis.json -e '{"alloc":map:put($json/alloc,"'$var'",{"balance":"1000000000000000000000000000"})}'
{
"alloc": {
"0x397559475c2d6cf48e10d33b1ab399ccb5f4546b": {
"balance": "1000000000000000000000000000"
},
"0xca843569e3427144cead5e4d5999a3d0ccf92b8e": {
"balance": "1000000000000000000000000000"
},
"0x0fbdc686b912d7722dc86510934589e0aaf3b55a": {
"balance": "1000000000000000000000000000"
},
"0x9186eb3d20cbd1f5f992a950d808c4495153abd5": {
"balance": "1000000000000000000000000000"
},
"0x0638e1574728b6d862dd5d3a3e0942c3be47d996": {
"balance": "1000000000000000000000000000"
}
}
}
------------------------------------------------------------------------------------------------
Stdin, using Xidel's read()-function (http://www.benibela.de/documentation/internettools/xpath-functions.html#pxp-read):
$ xidel -s genesis.json -e '{"alloc":map:put($json/alloc,read(),{"balance":"1000000000000000000000000000"})}'
0x397559475c2d6cf48e10d33b1ab399ccb5f4546b # Type or copy-paste this value.
{
"alloc": {
"0x397559475c2d6cf48e10d33b1ab399ccb5f4546b": {
"balance": "1000000000000000000000000000"
},
"0xca843569e3427144cead5e4d5999a3d0ccf92b8e": {
"balance": "1000000000000000000000000000"
},
"0x0fbdc686b912d7722dc86510934589e0aaf3b55a": {
"balance": "1000000000000000000000000000"
},
"0x9186eb3d20cbd1f5f992a950d808c4495153abd5": {
"balance": "1000000000000000000000000000"
},
"0x0638e1574728b6d862dd5d3a3e0942c3be47d996": {
"balance": "1000000000000000000000000000"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment