Ads were blocked - no problem. But keep in mind that developing HeidiSQL, user support and hosting takes time and money. You may want to send a donation instead.

JSON exporter does not escape strings

Miroticey1's profile image Miroticey1 posted 3 years ago in Import/Export Permalink

I want to export a result that contains HTML text column. I chose JSON because processing it would be easy. The exported JSON is invalid because the strings are not escaped, e.g. double quotes are unescaped.

kalvaro's profile image kalvaro posted 3 years ago Permalink

I can confirm that:

SELECT 'one"two' AS 'two"three'

... exports as:

{
    "table": "UnknownTable",
    "rows":
    [
        {
            "two"three": "one"two"
        }
    ]
}

(I admit I had never used it before.)

Code modification/commit 462dcba from ansgarbecker, 3 years ago, revision 5135
Escape quotes and stuff in JSON keys and values. See http://www.heidisql.com/forum.php?t=22747
Ads were blocked - no problem. But keep in mind that developing HeidiSQL, user support and hosting takes time and money. You may want to send a donation instead.
ansgar's profile image ansgar posted 3 years ago Permalink

Fixed in r5135

Miroticey1's profile image Miroticey1 posted 3 years ago Permalink

Thanks, I'm now on r5135 and the JSON is valid. However, HTML special chars get entity encoded and thats not needed. JSON strings can contain any Unicode character:

JSON string reference

kalvaro's profile image kalvaro posted 3 years ago Permalink

HTML special chars get entity encoded and thats not needed.

What do you mean exactly? JSON has nothing to do with HTML so either that being not needed it would be plain wrong. But I cannot reproduce it :-?

Miroticey1's profile image Miroticey1 posted 3 years ago Permalink

Sorry, should have included an example. I'm referring to a text column that contains HTML text. I want to export a result that contains this HTML text column. See this example. This forum drops HTML tags and entities, so I had to resort to codepad.

kalvaro's profile image kalvaro posted 3 years ago Permalink

Thank you. You're right in everything (bogus HTML escape in JSON and forum not being able to handle angle brackets even in code blocks).

Code modification/commit cdea092 from ansgarbecker, 3 years ago, revision 5137
Don't encode html entities but escape quotes in JSON grid export. See http://www.heidisql.com/forum.php?t=22747#p22783
ansgar's profile image ansgar posted 3 years ago Permalink

r5137 escapes quotes in JSON "query" values, and removes encoding of HTML entities.

Please login to leave a reply, or register at first.