Comments (2)
This appears to be an issue which is observed for merging incompatible nodes.
That is, given, a.json
and b.json
, each of which is a JSON object.
And at the same path .node
, b.json
has an array and the other has an atom (string, number, ...).
from jq-front.
#!/bin/env bash
set -eu +o posix -o pipefail
function debug() {
echo "${@}" >&2
}
function abort() {
debug "${@}"
exit 1
}
# Latter overrides former
function _merge_object_nodes() {
local _a="${1}"
local _b="${2}"
local _error
_error=$(mktemp)
debug "merging _a:'${_a}' and _b:'${_b}'"
# shellcheck disable=SC2016
jq -r -c -n --argjson a "${_a}" --argjson b "${_b}" '#----
def value_at($n; $p):
$n | getpath($p);
def setvalue_at($n; $p; $v):
$n | setpath($p; $v);
def type_of($v):
$v | type;
def setvalue_at($n; $p; $v):
$n | if type_of($v)=="object" or type_of($v)=="array" then
if type_of(value_at($n; $p))!="object" and type_of(value_at($n; $p)!="array") then
setvalue_at(.; $p; $v)
else
.
end
else
setvalue_at(.; $p; $v)
end;
def merge_objects($a; $b):
$b | [paths(scalars_or_empty)]
| reduce .[] as $p ($a; setvalue_at(.; $p; value_at($b; $p)));
merge_objects($a; $b)' || {
abort "Failed to merge object nodes:'${_a}' and '${_b}': error: ${_error}"
}
}
_merge_object_nodes '{"key":"value"}' '{"key":["elem1"]}'
from jq-front.
Related Issues (20)
- A boolean value is not rendered when it is placed deeper than level-2 HOT 1
- Allow using "-" in a node name to be referenced
- Print out stderr when a templating fails
- Reference (ref) with a current (cur) path from inside an array results in an error HOT 1
- Improve scalabitliy
- Provide a way to remove a node from the inherited JSON
- Implement the `$includes` feature HOT 2
- Make it possible to override `text` (atom) node with an array or an object node
- Implement `$this` attribute
- Improve error reporting feature during the `templating`
- Request to Edit Installation Procedure HOT 1
- A local node containing a white space doesn't render
- Reference to an empty string value doesn't render
- jq-front cannot find a node on inheritance with a default environment variable values
- Drop validation feature
- Add a doc about arrayappend
- Key containing command substitutable string put jq-front in an infinite loop
- Implement key-side substitution feature
- Fix temporary directory handling issue
- An error message "_misctemp_files_dir: command not found" is output
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jq-front.