FR: Add a json
function in template language for serializing strings
#5648
Labels
enhancement
New feature or request
Is your feature request related to a problem? Please describe.
It is currently impossible for a tool to reliably use output of commands
jj log
andjj op log
. By using template we can impose a structure on the output, but some fields, like commit messages or commands that contain template can have arbitrary strings in them, and there is no way to split them and detect when an entry ends.Describe the solution you'd like
Add a function
json
which receives a string and serialize it as a json string, replace its problematic characters like end line with escapes, and surround it with"
. If/when template language gets dynamic objects in future, this function can be extended to convert them to json too.Describe alternatives you've considered
A dedicated
jj api
command like the one proposed in #3219 can solve this problem, but it needs massive design and maintenance. This function is a small addition that can coexist with future solutions.The text was updated successfully, but these errors were encountered: