Read JSON file while interpolate a string

#1

Hi. Suppose I have a .JSON file like the following.

{ 
   "path": "$dir/movies"
}

The julia code is like the following:

using LazyJSON
strJSONFl = String(read("myFile.json"))
v = LazyJSON.parse(strJSONFl)  
dir = @__DIR__   
println( v["path"] ) 

Then, this will output “$dir/movies”. There is this extra backslash in the very beginning of the output, which I need to get rid of. Because I’d like to call eval(v["path"]) afterwards.

Have you ever encountered similar situations?

#2

I would advise against evaling unsanitized, arbitrary code read from a string/file.

You can find and replace the $dir with a regex, or just matching agains the string raw"$dir".

2 Likes