To find the extension of a JSON file in Go, you can use the filepath
and strings
packages. Here's an example code snippet to achieve this:
main.go257 chars15 lines
In this code, we first define the filepath of the JSON file in the filePath
variable. Then, we use the filepath.Ext()
function to get the extension of the file (including the '.' prefix). Finally, we remove the '.' prefix using the strings.TrimPrefix()
function and print the extension.
gistlibby LogSnag