Skip to content

Instantly share code, notes, and snippets.

@Reino17
Last active July 5, 2025 17:09
Show Gist options
  • Select an option

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

Select an option

Save Reino17/e5bdce48b6e0f0824c707a7fed197f78 to your computer and use it in GitHub Desktop.
$ xidel -se 'json-doc("Input1.json")(),json-doc("Input2.json")()'
$ xidel -se '
json-doc("Input1.json")(),
json-doc("Input2.json")()
'
{
"A": "Name 1",
"B": "1.1",
"C": "2"
}
{
"A": "Name 2",
"B": "3.2",
"C": "4"
}
{
"A": "Name 2",
"B": "5",
"C": "6"
}
{
"A": "Name 3",
"B": "7",
"C": "8"
}
$ xidel -se 'let $src:=(json-doc("Input1.json")(),json-doc("Input2.json")()) return $src/A'
$ xidel -se '
let $src:=(
json-doc("Input1.json")(),json-doc("Input2.json")()
)
return
$src/A
'
Name 1
Name 2
Name 2
Name 3
$ xidel -se 'let $src:=(json-doc("Input1.json")(),json-doc("Input2.json")()) return distinct-values($src/A)'
$ xidel -se '
let $src:=(
json-doc("Input1.json")(),
json-doc("Input2.json")()
)
return
distinct-values($src/A)
'
Name 1
Name 2
Name 3
$ xidel -se 'let $src:=(json-doc("Input1.json")(),json-doc("Input2.json")()) for $name at $i in distinct-values($src/A) return ($i,$src[A=$name])'
$ xidel -se '
let $src:=(
json-doc("Input1.json")(),
json-doc("Input2.json")()
)
for $name at $i in distinct-values($src/A)
return
($i,$src[A=$name])
'
1
{
"A": "Name 1",
"B": "1.1",
"C": "2"
}
2
{
"A": "Name 2",
"B": "3.2",
"C": "4"
}
{
"A": "Name 2",
"B": "5",
"C": "6"
}
3
{
"A": "Name 3",
"B": "7",
"C": "8"
}
$ xidel -se 'let $src:=(json-doc("Input1.json")(),json-doc("Input2.json")()) for $name in distinct-values($src/A) let $obj:=$src[A=$name] return if (count($obj) gt 1) then map:merge(for $key in map:keys($obj[1]) return map:entry($key,if ($obj[1]($key) castable as decimal) then string($obj[1]($key) + $obj[2]($key)) else $obj[1]($key))) else $obj'
$ xidel -se '
let $src:=(
json-doc("Input1.json")(),
json-doc("Input2.json")()
)
for $name in distinct-values($src/A)
let $obj:=$src[A=$name]
return
if (count($obj) gt 1)
then map:merge(
for $key in map:keys($obj[1]) return
map:entry(
$key,
if ($obj[1]($key) castable as decimal)
then string($obj[1]($key) + $obj[2]($key))
else $obj[1]($key)
)
)
else $obj
'
{
"A": "Name 1",
"B": "1.1",
"C": "2"
}
{
"A": "Name 2",
"B": "8.2",
"C": "10"
}
{
"A": "Name 3",
"B": "7",
"C": "8"
}
$ xidel -se 'array{let $src:=(json-doc("Input1.json")(),json-doc("Input2.json")()) for $name in distinct-values($src/A) let $obj:=$src[A=$name] return if (count($obj) gt 1) then map:merge(for $key in map:keys($obj[1]) return map:entry($key,if ($obj[1]($key) castable as decimal) then string($obj[1]($key) + $obj[2]($key)) else $obj[1]($key))) else $obj}'
$ xidel -se '
array{
let $src:=(
json-doc("Input1.json")(),
json-doc("Input2.json")()
)
for $name in distinct-values($src/A)
let $obj:=$src[A=$name]
return
if (count($obj) gt 1)
then map:merge(
for $key in map:keys($obj[1]) return
map:entry(
$key,
if ($obj[1]($key) castable as decimal)
then string($obj[1]($key) + $obj[2]($key))
else $obj[1]($key)
)
)
else $obj
}
'
[
{
"A": "Name 1",
"B": "1.1",
"C": "2"
},
{
"A": "Name 2",
"B": "8.2",
"C": "10"
},
{
"A": "Name 3",
"B": "7",
"C": "8"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment