Serialize JSON into an escaped single-line string literal for contracts and scripts, and back.
Loading tool
About JSON Serializer
Turn JSON into an escaped, single-line string literal you can paste into Solidity, JavaScript or a deploy script, and turn an escaped literal back into validated, pretty-printed JSON. You can choose double, single or backtick quotes, minify first and escape non-ASCII characters as \uXXXX. A ready-made Solidity string constant is shown for double or single quotes.
Common uses
- Embed NFT metadata JSON as a string constant in a contract
- Put a JSON config or ABI into a JavaScript or TypeScript deploy script
- Recover readable JSON from an escaped string copied out of logs or source code
- Check that an escaped JSON string is still valid JSON
FAQ
- How do I put JSON inside a Solidity string?
- Escape every double quote and backslash (or wrap the string in single quotes and escape those instead) and keep it on one line. Solidity string literals cannot contain raw newlines.
- Can I use backticks in Solidity?
- No. Solidity string literals use double or single quotes only; backtick template strings are a JavaScript feature.
- Why escape non-ASCII characters?
- Regular Solidity string literals only allow ASCII characters; other text needs the unicode"..." prefix or escape sequences. Escaping as \uXXXX keeps the literal plain ASCII.