input: Write a function to extract features from a json string and return a dictionary of extracted features. The function should take a json string as input, parse it, and return a dictionary containing the 'id' and 'title' from the json object, as well as the length of the 'body' text. If the input string is not a valid json format, the function should 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": 27}
  assert feature_extraction('{"id":112,"title":"Another title","body":"Short"}') == {"id": 112, "title": "Another title", "body_len": 5}
  assert feature_extraction('{"id":113,"body":"No title"}') == {"id": 113, "title": None, "body_len": 9}
  assert feature_extraction('{"id":114,"title":"With a body that is missing"}') == {"id": 114, "title": "With a body that is missing", "body_len": 0}
  assert feature_extraction('{invalid json}') == {}
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 {}