-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add json template #74
Conversation
Congratulations 🍻. DeepCode analyzed your code in 0.221 seconds and we found no issues. Enjoy a moment of no bugs ☀️. 💬 This comment has been generated by the DeepCode bot, installed by the owner of the repository. The DeepCode bot protects your repository by detecting and commenting on security vulnerabilities or other critical issues. |
It would be really preferable not to introduce format-dependent code into the template engine. We are aiming to have it as simple as possible. Can't JSON be correctly expressed by using just the template? |
Hi, I understand your point, but I found problems with right/left curly brace with the current template_engine. |
I mean, I've tested to add html entities ({ or {) and is didin't work. If I use "{" I think template engine interpret it like a start of a function, like "{findings:repeat:" |
Perhaps we can fix that then and add escapable curly braces. I would really
prefer to not introduce format-based logic.
…On Fri, Feb 21, 2020, 14:59 cmorell ***@***.***> wrote:
I mean, I've tested to add html entities ({ or {) and is didin't work. If
I use "{" I think template engine interpret it like a start of a function,
like "{findings🔁"
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#74>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC2BANUIAIBNFGS4AFIMG3REAXD3ANCNFSM4KZIMTVQ>
.
|
I just took a look at it. Since the template engine is based on format(),
you can just double the curly braces to get it working. For example:
{{{tm.name}}}
prints out:
{my test tm}
if run as template with the sample tm.py. Can you try your JSON template
with this in mind?
thanks!
On Sat, Feb 22, 2020 at 8:54 AM Izar Tarandach <izar.tarandach@gmail.com>
wrote:
… Perhaps we can fix that then and add escapable curly braces. I would
really prefer to not introduce format-based logic.
On Fri, Feb 21, 2020, 14:59 cmorell ***@***.***> wrote:
> I mean, I've tested to add html entities ({ or {) and is didin't work. If
> I use "{" I think template engine interpret it like a start of a function,
> like "{findings🔁"
>
> —
> You are receiving this because your review was requested.
> Reply to this email directly, view it on GitHub
> <#74>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAC2BANUIAIBNFGS4AFIMG3REAXD3ANCNFSM4KZIMTVQ>
> .
>
|
…ormat wihout any change
Hi, Solution found in: https://stackoverflow.com/questions/51562600/escaping-curly-braces-in-string-to-be-formatted-an-undefined-number-of-times
After it, we need to change last occurrence of }, to } to make a valid json |
If you need a JSON output you should generate it in Python after building the model, not using a template: tm = TM("some model")
# add assets and dataflows
tm.resolve()
data = {
"name":tm.name,
"description":tm.description,
"threats": [{"name": f.id} for f in TM._BagOfFindings],
}
with open('report.json', 'w') as f:
json.dump(data, f) |
Hi @nineinchnick Just let me know |
Generating structured data using an unstructured template creates a risk of the output file to be invalid, because it's easy to make a typo in the template or not properly escape template data. If you save a JSON file from Python it's always going to be a correct JSON file and whatever you feed it to will be able to parse it. If you generate it using a template and make a typo, like a missing brace or extra comma, it's hard to pin point exactly where is it. That's the issue you're currently having - an extra comma. |
#102 should also address this but in a more robust way |
Adding json template
now, PR straight to master