input: Write a function to parse a given JSON-formatted string into a dictionary. If the input string is not a valid JSON, the function should return None.
  assert parse_json('{"name": "John", "age": 30, "address": {"city": "New York", "state": "NY"}}')=={'name': 'John', 'age': 30, 'address': {'city': 'New York', 'state': 'NY'}}
  assert parse_json('{"name": "Alice", "age": 25}')=={'name': 'Alice', 'age': 25}
  assert parse_json('invalid json string')==None
  assert parse_json('{"key": "value",}')==None
  assert parse_json('[]')==[]
output: def parse_json(json_str):
      try:
          return json.loads(json_str)
      except json.JSONDecodeError:
          return None