opened
KrishnaNagar
username_0
INPUT:
{
	"rating": {
		"0_er_MN": "Vijay",
		"0_we_MN": "Godhra",
		"0_sw_MN": "true",
		"1_er_ZM": "Kiran",
		"1_we_ZM": "Swiden",
		"1_sw_ZM": "false",
		"2_er_AM": "Ruchi",
		"2_we_AM": "Swiden",
		"2_sw_AM": "true"
	}
}
SPEC:
[
  {
    "operation": "shift",
    "spec": {
      "rating": {
        "*_sw_*": {
          "@": "rate[&(0,1)].sw"
        },
        "*_er_*": "rate[&(0,1)].er",
        "*_we_*": "rate[&(0,1)].we"
      }
    }
  }
]
OUTPUT:
{
  "rate" : [ {
    "er" : "Vijay",
    "sw" : "true",
    "we" : "Godhra"
  }, {
    "er" : "Kiran",
    "sw" : "false",
    "we" : "Swiden"
  }, {
    "er" : "Ruchi",
    "sw" : "true",
    "we" : "Swiden"
  } ]
}
EXPECTED OUTPUT:
{
  "rate" : [ {
    "er" : "Vijay",
    "sw" : "true",
    "we" : "Godhra"
  }, {
    "er" : "Ruchi",
    "sw" : "true",
    "we" : "Swiden"
  } ]
}
CONDITION:
Here, rating have keys like,    *_X_* where  * is dynamic and X is static and can have value er/sw/we.  Here if  *_sw_* has true value then only *'s corrosponding 3 values should be in output json.
Condition check where some part of key is static and some is dynamic
issue
created
milosimpson
username_1
Spec :
```
[
  {
    "operation": "shift",
    "spec": {
      "rating": {
        // first group the leading digit 0,1,2
        // also rewrite "0_we_MN" -> "we"
        "*_*_*": "temp.&(0,1).&(0,2)"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "temp": {
        "*": {
          "sw": {
            "true": {
              // match down to "sw" : true
              // grab the whole object and append it 
              // to "rate[]" which will always be an array
              "@2": "rate[]"
            }
          }
        }
      }
    }
  }
]
```

Also when pasting in JSON if you put three ` marks Github will show it nicer.
See https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown
comment
closed
jsurls
username_2
issue