input: Write a function to parse a json-formatted string and convert it into a dictionary. The function should return the dictionary. If the input string is not a valid json format, the function should raise a ValueError. If the input string is empty, the function should return an empty dictionary.
  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('') == {}
  try:
      parse_json('invalid json string')
  except ValueError:
      pass
output: def parse_json(json_str):
      if not json_str:
          return {}
      try:
          return json.loads(json_str)
      except json.JSONDecodeError:
          raise ValueError("Invalid JSON format")