Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

json 'dumps' filter for creating javascript with mako

Open
#229 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
javascript, python
Domain
backend, web-dev

Research direction

The issue names no files or tests. Start by locating Mako's existing filtering and escaping entry points and related template-output tests; use the examples to define the expected JSON-to-JavaScript escaping behavior, then add coverage showing that both single and double quotes remain valid.

Written by the indexing model from the issue text.

Description

bug

Migrated issue, originally created by jvanasco (@jvanasco)

I ran into some issues with Mako when trying to make javascript using the output of json.dumps

# in python
python_dict = { "hello" : """This is an example object I am using some 'single quotes' and "double quotes".""", }

usually i can just disable filtering in mako :

// in js template 
var payload = '${simplejson.dumps(python_dict)|n}';

unfortunately in this case the single-quotes break. we get this

// in js generated
var payload = '{"hello": "This is an example object I am using some 'single quotes' and \"double quotes\"."}'

this appears to work fine :

// in js template 
var payload = '${simplejson.dumps(python_dict).encode('string-escape')|n}';

which generates

// in js generated
var payload = {"hello": "This is an example object I am using some \'single quotes\' and \\"double quotes\\"."}

there are a handful of miscellaneous JS+Mako questions floating on StackOverflow and blogs... so i think it might be worthwhile to have an official json escaping method in mako templates.

Dominant language
Python
Stars
459
Forks
96
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sqlalchemy/mako

All issues in sqlalchemy/mako

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.