input: Write a function to extract features from a JSON string. The function should return a dictionary containing the 'id', 'title', and the length of the 'body' text. If the JSON string is empty or fails to parse, return an empty dictionary.
  def feature_extraction(input_str):
      import json
      try:
          data = json.loads(input_str)
          features = {
              "id": data.get("id"),
              "title": data.get("title"),
              "body_len": len(data.get("body", ""))
          }
          return features
      except json.JSONDecodeError:
          return {}
          
  assert feature_extraction('{"id":111,"title":"This is a sample title","body":"This is a sample body text"}')=={"id": 111, "title": "This is a sample title", "body_len": 29}
  assert feature_extraction('{"id":222,"title":"Another title","body":"Another body"}')=={"id": 222, "title": "Another title", "body_len": 13}
  assert feature_extraction('{"id":333,"title":"","body":""}')=={"id": 333, "title": "", "body_len": 0}
  assert feature_extraction('{}')=={"id": None, "title": None, "body_len": 0}
  assert feature_extraction('')=={}
output: 
  def feature_extraction(input_str):
      import json
      try:
          data = json.loads(input_str)
          features = {
              "id": data.get("id"),
              "title": data.get("title"),
              "body_len": len(data.get("body", ""))
          }
          return features
      except json.JSONDecodeError:
          return {}
  