Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

using just.net to transform json, Is there a way to remove a complex type field that has no child with value?

$
0
0

sample input json:

{
  "parent1": {
    "child2": "value"
  }
}

currently, if i don't want to show a non-existing field, i will use "#ifgroup(#exists(" function combination.

Consider this transformer:

{ 
  "t_parent1": {
    "#ifgroup(#exists($.parent1.child1))" : {
      "t_child1": "#valueof($.parent1.child1)"
    },
    "#ifgroup(#exists($.parent1.child2))" : {
      "t_child2": "#valueof($.parent1.child2)"
    }
  }
  "t_parent2": {
    "#ifgroup(#exists($.parent2.child1))" : {
      "t_child1": "#valueof($.parent2.child1)"
    },
    "#ifgroup(#exists($.parent2.child2))" : {
      "t_child2": "#valueof($.parent2.child2)"
    }
  }
}

this will output:

{ 
  "t_parent1": {
      "t_child2": "value"
  },
  "t_parent2": {
  }
}

now, if i don't want t_parent2 to be visible in the current output since it has no child, is it possible in just.net to remove it considering other inputs might include parent2 with child nodes?

like

{
  "#ifgroup(#exists($.parent2.child1) **OR** #ifgroup(#exists($.parent2.child2))": {
    "parent2" {
      ...
    }
  }
}

Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>