Skip to content
Advertisement

GROOVY I am getting random backslashes when creating JSON file in Folder

I am having trouble compiling the JSON file. This is my method (the main method just has the name of the method I am writing this code in it so I did not include the main method in here.)

JavaScript

my output in the console does come out right like this

[commands:[{"includeCommandName":true,"path":"${BUILTIN_EXE(command)}","name":"upload"},{"includeCommandName":true,"path":"${BUILTIN_EXE(command)}","name":"file_info"}]]

but sending it to the JSON file it comes out like this

{"commands":"[{"includeCommandName":true,"path":"${BUILTIN_EXE(command)}","name":"upload"},{"includeCommandName":true,"path":"${BUILTIN_EXE(command)}","name":"file_info"}]"}

I understand that JSON backslash is a special character so I expected it to be only around the :”${BUILTIN_EXE(command)} but it is showing up everywhere where I did not even have a backslash.

Advertisement

Answer

You don’t have “random backslashes”, you have double-quoted JSON, since you’re using JsonOutput twice. json_str is a string with JSON in it, and then you’re wrapping that as a JSON value inside more JSON.

Advertisement