jsontrim

takes a JSON object, removes specified subtrees and trims arrays returns a pretty printed string

usage

require 'jsontrim'

before = "{ \"foo\": {\n    \"one\": { \"a\": 1, \"b\": {\"c\": 2} },\n    \"two\": \"value\",\n    \"three\": { \"b\": [1,2,3] }},\n  \"bar\": [1,2,3,4,5] }\n"

blacklist = [
  "foo:!two",   # delete the value before['foo']['two']
  "foo:*:!b",   # delete all the keys called "b" nested two levels under "foo"
  "bar:+"       # only keep the first element of the foo-list
]

after = JSONTrim.cut(before, :ignore => blacklist)

{
  "foo": {
    "two": ...,
    "three": {
       "b": [ ... ]
    },
    "one": {
      "a": 1,
      "b": { ... }
    }
  },
  "bar": [
    1,
    ...
  ]
}