Yasha .json template error
See original GitHub issueI have a valid .json file that works if I use it as is.
This .json file has {{ .foo }}
variables in it, which are internally processed ( these are not jinja variables) .
I am attempting to take this .json file and run it through the Yasha template command to create more .json files using jinja {{ bar }}
to replace other hard coded variable values in the .json file.
If I run the .json file as is, it complains about the .json {{ .foo }}
variables as expected. These variables can not be replaced or removed so I used the {% raw %}
as described here to omit them.
My syntax looked like this: {% raw %} ...code line...{{ .foo } }...more code...{% endraw %}
.
This should have allowed Yasha to ignore the .json variables with no complaints. Instead I receive the following error:
Traceback (most recent call last):
File "/usr/local/bin/yasha", line 11, in <module>
load_entry_point('yasha==3.1', 'console_scripts', 'yasha')()
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/yasha/scripts/yasha.py", line 156, in cli
vardict.update(parse_variables(variables, ex["variable_parsers"]))
File "/usr/local/lib/python3.5/dist-packages/yasha/scripts/yasha.py", line 35, in parse_variables
return parser.parse(file)
File "/usr/local/lib/python3.5/dist-packages/yasha/parsers/json.py", line 35, in parse
return json.loads(file.read().decode('utf8'))
File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.5/json/decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
I think this is because a json validator is being run on the file first, before jinja is used. I didn’t expect any json validating.
If I change the file extension from .json to .txt it has no complaints and completes its jinja parsing correctly. I think because there is no json validating in this file extension.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
This should be fixed in 4.1. Thanks for reporting.
Yasha does not validate the template.