Synthoid / ExportSheetData

Add-on for Google Sheets that allows sheets to be exported as JSON or XML.
MIT License
236 stars 46 forks source link

newline \n in string gets converted to \\n on export/visualise #90

Open HawkenKing opened 5 years ago

HawkenKing commented 5 years ago

is there a setting to make it stay as \n?

Synthoid commented 5 years ago

Does your string use the literal sting \n? For example:

The quick brown fox

Jumped over the lazy dog.

vs.

The quick brown fox\n\nJumped over the lazy dog.

imtrobin commented 5 years ago

I have the same problem, I use the 2nd version

Synthoid commented 5 years ago

Ah, you should use the top method to export newline chars. There's no real easy way to detect the string \n as a newline char instead of the literal sting itself, so I can't do much to support that without making string exports go through a bunch of hoops unfortunately.

imtrobin commented 5 years ago

Actually, json unesacpe is able to do so, e.g this tool

https://www.freeformatter.com/json-escape.html

Synthoid commented 5 years ago

Hmm, I just tried the following string with that tool: Test\n2

And got the escaped string: Test\\n2

Which is what ESD does. I wasn't saying it's difficult to detect the newline char and escape it as \n, I was saying it would be complicated to detect the string \n as a newline char because it is made up of two chars (\ and n) instead of one char (\n) and that may be intentional on the user's part so I'm hesitant to inject forced interpretation into the parser.

imtrobin commented 5 years ago

You should be using unescape, not escape. But what I meant is , is there a way to disable this auto escape?

HawkenKing commented 4 years ago

Hi @Synthoid could you clarify "top method"?

I used the plugin last year (and before) with no problems, it always kept \n

now it makes \\n in the output, which isn't parseable json.

I'm using this for making language files in games, I need to decide with the translators where carriage returns are with \n so need this in the output, can't use visual carriage returns (which close the cell in docs anyway)

Synthoid commented 4 years ago

@HawkenKing By top method, I mean using standard visual carriages in your cell:

Like

This

Instead of:

Like\n\nThis

You can make newlines like this by pressing ctrl + enter when editing the cell, with those newline chars being escaped as a \n char in the exported JSON. Last year, I updated the way JSON was built to use the standard JSON utility in JavaScript instead of manually building a string myself. That fixed a bunch of overlooked formatting issues that the old method had. This ensures the JSON is valid, but can lead to some undesired data changes for longtime users. For that I apologize!

@imtrobin I am hesitant to disable auto escape, as that will affect JSON formatting for all values. Yet given that the point of ESD is to be able to configure your data, I suppose it couldn't hurt. I'm reopening this issue for the time being.