<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def addJsonDirectory(self, directory, test=None):
 """Adds data from json files in the given directory."""


    for filename in os.listdir(directory):
      try:
        fullPath = os.path.join(directory, filename)
        if not test or test(filename, fullPath):
          with open(fullPath) as f:
            jsonData = json.load(f)
            name, _ = os.path.splitext(filename)
            self.addSource(name, jsonData)

      except ValueError:
        continue