Need help understanding csv file with js


I am working on converting json to csv file and i have managed to get it working by referring to this fiddle

The part which i am still unable to understand is how link.href able to create a file using a encoded string. I did look at how the string begins with the format and encoding information, but what i do not understand is how href attribute is able to create a file with the string.

Any explanation or link explaining the encoding will be very helpful as i have searched hard and not found an good enough explanation.

The function JSONToCSVConvertor converts a JSON object to a CSV format text file.

Lines 15 through 61 is the code sections that perform the conversion process.

I hope I am understanding your question correctly. I may not be.

At line 76 marking the anchor element with the ‘download’ attribute signals the browser to interact with the OS in order to create a file rather than display it as described here:

I apologize if the question was not clear. My confusion is because i always understood that href attribute was only specifying the path. The fiddle i mentioned is using the encoded string which is the entire content of the file created. I did not find any other examples explaining the usage of href attribute in this manner.

Haven’t seen such usage either, so I did my research and it is indeed a valid technique:

1 Like

Thank you. I will go through the spec to see if i can find more details on the topic to see which files can be created using this technique right now i am limited to csv tried to create excel but did not succeed it seems it will not be possible through the front end.