You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
for example if user pass ['Admin.resource1', 'Workspace'] so expeceted ouput json will be Note '.' 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.
First off, it's a recursive problem so we'd need to use Ref in order to get that problem.
Then, it's a filtration problem, so we will need to use the SKIP marker object to drop things which don't match.
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 remap() recursion helper from boltons. I don't want to over-promise that glom is the right solution. But, I'll take a shot at it.
Reformulating the problem:
we want to recurse on "child" attribute of dict
for every dict, if the "node" attribute is in the input set, completely hold onto it and all child nodes
on the way back out, we want to drop any nodes that weren't included in the result set, or whose children weren't included in the result set
node_spec=Ref("node-spec",
Or(
# case 1: this node is in the input; return it and all childrenAnd(lambdat: t["node"] int[S]["input-nodes"], T),
# case 2: one of the children is in the inputAnd((
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.
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: