my goal is to create a JSON file that has all its references expanded. My code for that looks like that:
prev_cwd = os.getcwd()
os.chdir(args.infile.parent)
print(os.getcwd())
in_dict = jsonref.loads(in_text, base_uri=str(args.infile))
in_text = json.dumps(in_dict)
os.chdir(prev_cwd)
"components": {
"$ref": "file:common.json#/launch"
},
/home/floli/workspace/myproject/evaluation_launcher/config/schemas
Traceback (most recent call last):
File "/home/floli/.local/lib/python3.8/site-packages/proxytypes.py", line 252, in __subject__
return self.cache
File "/home/floli/.local/lib/python3.8/site-packages/proxytypes.py", line 176, in __getattribute__
return _oga(self, attr)
AttributeError: 'JsonRef' object has no attribute 'cache'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.8/urllib/request.py", line 1511, in open_local_file
stats = os.stat(localfile)
FileNotFoundError: [Errno 2] No such file or directory: '/common.json'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/floli/.local/lib/python3.8/site-packages/jsonref.py", line 178, in callback
base_doc = self.loader(uri)
File "/home/floli/.local/lib/python3.8/site-packages/jsonref.py", line 299, in __call__
result = self.get_remote_json(uri, **kwargs)
File "/home/floli/.local/lib/python3.8/site-packages/jsonref.py", line 316, in get_remote_json
result = json.loads(urlopen(uri).read().decode("utf-8"), **kwargs)
File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.8/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/usr/lib/python3.8/urllib/request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/usr/lib/python3.8/urllib/request.py", line 1489, in file_open
return self.open_local_file(req)
File "/usr/lib/python3.8/urllib/request.py", line 1528, in open_local_file
raise URLError(exp)
urllib.error.URLError: <urlopen error [Errno 2] No such file or directory: '/common.json'>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "visualize_json.py", line 33, in <module>
in_text = json.dumps(in_dict)
File "/usr/lib/python3.8/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python3.8/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
File "/home/floli/.local/lib/python3.8/site-packages/proxytypes.py", line 175, in __getattribute__
return getattr(self.__subject__, attr)
File "/home/floli/.local/lib/python3.8/site-packages/proxytypes.py", line 176, in __getattribute__
return _oga(self, attr)
File "/home/floli/.local/lib/python3.8/site-packages/proxytypes.py", line 134, in wrapper
return method(self, *args, **kwargs)
File "/home/floli/.local/lib/python3.8/site-packages/proxytypes.py", line 254, in __subject__
self.cache = super(LazyProxy, self).__subject__
File "/home/floli/.local/lib/python3.8/site-packages/proxytypes.py", line 134, in wrapper
return method(self, *args, **kwargs)
File "/home/floli/.local/lib/python3.8/site-packages/proxytypes.py", line 240, in __subject__
return self.callback()
File "/home/floli/.local/lib/python3.8/site-packages/proxytypes.py", line 134, in wrapper
return method(self, *args, **kwargs)
File "/home/floli/.local/lib/python3.8/site-packages/jsonref.py", line 180, in callback
self._error("%s: %s" % (e.__class__.__name__, unicode(e)), cause=e)
File "/home/floli/.local/lib/python3.8/site-packages/proxytypes.py", line 134, in wrapper
return method(self, *args, **kwargs)
File "/home/floli/.local/lib/python3.8/site-packages/jsonref.py", line 223, in _error
raise JsonRefError(
jsonref.JsonRefError: URLError: <urlopen error [Errno 2] No such file or directory: '/common.json'>
I have verified that the current working directory is set to where both files are, input and common.json
. I am not really sure about the meaning of the base_uri
argument and how it should look like?