-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract nodes from json based on user input preserveing a portion of the higher level object as well #247
Comments
First off, it's a recursive problem so we'd need to use Then, it's a filtration problem, so we will need to use the Additionally, there are two inputs here: one is the nested nodes, the other is the list of attribute nodes. This might be better solved with a direct recursion or the Reformulating the problem:
node_spec = Ref("node-spec",
Or(
# case 1: this node is in the input; return it and all children
And(lambda t: t["node"] in t[S]["input-nodes"], T),
# case 2: one of the children is in the input
And((
A.node,
"child",
[Ref("node-spec")],
Merge(S.node, Oof, even as I'm writing this I can tell it's a bad fit for glom; there are multiple inputs and a lot of internal state. This is really just a recursion problem. I'm not going to bother trying to finish it, it would be really tortured. def filter_node(cur, to_include):
if cur["node"] in to_include:
return cur
children = []
for child in cur["child"]:
filtered = filter_node(child)
if filtered:
children.append(filtered)
if children:
return {**cur, "child": children}
return None |
I need to extract object from the given json based on the node chain passed by user and neglect those which are not in
user input, then create a new json object
my master json is :
for example if user pass
['Admin.resource1', 'Workspace']
so expeceted ouput json will beNote '.' in element of user inputted list means that node have child nodes and new json will be having all those child node details including parent node details.
or another example is :
['Admin.resouce2', 'workspace.system1']
then expected json will be:or if only single node passed
['Admin']
then output json will be:or another example is :
['Admin.resouce1', 'Admin.resouce2']
then expected json will be:How would I achieve that using Glom?
The text was updated successfully, but these errors were encountered: