input: Write a function to parse a given json-formatted string into a dictionary. If the input is invalid or the string is not in json format, return an empty dictionary. 
  
  def parse_json_to_dict(json_str):
      try:
          return json.loads(json_str)
      except json.JSONDecodeError:
          return {}
  
  assert parse_json_to_dict('{"name": "John","age": 30,"address": {"city": "New York","state": "NY"}}')=={'name': 'John', 'age': 30, 'address': {'city': 'New York', 'state': 'NY'}}
  assert parse_json_to_dict('{"name": "Alice","age": 25}')=={'name': 'Alice', 'age': 25}
  assert parse_json_to_dict('invalid json string')=={}
  assert parse_json_to_dict('')=={}
  assert parse_json_to_dict('{"name": "Bob","age": 40, "address": {"city": "Los Angeles","state": "CA"}}')=={'name': 'Bob', 'age': 40, 'address': {'city': 'Los Angeles', 'state': 'CA'}}
output: def parse_json_to_dict(json_str):
      try:
          return json.loads(json_str)
      except json.JSONDecodeError:
          return {}