-1

I'm having a problem inserting JSON into JSON columns. I'm trying to insert the basic "{}", but it gives a fatal error. Theoretically, I can insert JSON into a text data type, but this is a perversion. Can you help me?

Image 1

{
    "pma_version": "5.2.1deb1+focal2",
    "browser_name": "CHROME",
    "browser_version": "135.0.0.0",
    "user_os": "Win",
    "server_software": "Apache/2.4.63 (Ubuntu)",
    "user_agent_string": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36",
    "locale": "ru",
    "configuration_storage": "enabled",
    "php_version": "8.3.19",
    "script_name": "index.php",
    "exception_type": "js",
    "exception": {
        "mode": "stack",
        "name": "SyntaxError",
        "message": "Unexpected end of JSON input",
        "stack": [
            {
                "line": "342",
                "func": "",
                "context": [
                    "            if (lastException === ex) {",
                    "                processLastException();",
                    "            }",
                    "        }, (stack.incomplete ? 2000 : 0));",
                    "",
                    "        throw ex; // re-throw to propagate to the top level (and cause wind//...",
                    "    }",
                    "",
                    "    report.subscribe = subscribe;",
                    "    report.unsubscribe = unsubscribe;",
                    "    return report;"
                ],
                "uri": "js/vendor/tracekit.js?v=5.2.1deb1%2Bfocal2",
                "scriptname": "js/vendor/tracekit.js"
            },
            {
                "func": "JSON.parse",
                "line": "",
                "column": "",
                "context": "",
                "uri": "index.php?",
                "scriptname": "index.php"
            },
            {
                "func": "Object.saveEditedCell",
                "line": "1452",
                "column": "63",
                "context": [
                    "        let isValueUpdated;",
                    "        if ($thisField.attr('data-type') !== 'json') {",
                    "          isValueUpdated = thisFieldParams[fieldName] !== Functions.getCell//...",
                    "        } else {",
                    "          const JSONString = Functions.stringifyJSON(thisFieldParams[fieldN//...",
                    "          isValueUpdated = JSONString !== JSON.stringify(JSON.parse(Functio//...",
                    "        }",
                    "        if (g.wasEditedCellNull || isValueUpdated) {",
                    "          needToPost = true;",
                    "        }",
                    "      }"
                ],
                "uri": "js/dist/makegrid.js?v=5.2.1deb1%2Bfocal2",
                "scriptname": "js/dist/makegrid.js"
            },
            {
                "func": "Object.saveOrPostEditedCell",
                "line": "1474",
                "column": "21",
                "context": [
                    "     *",
                    "     * @param options Optional, this object contains a boolean named move (//...",
                    "     *                and a <td> to which the grid_edit should move",
                    "     */",
                    "    saveOrPostEditedCell: function (options) {",
                    "      var saved = g.saveEditedCell();",
                    "      // Check if $cfg['SaveCellsAtOnce'] is false",
                    "      if (!g.saveCellsAtOnce) {",
                    "        // Check if need_to_post is true",
                    "        if (saved) {",
                    "          // Check if this function called from 'move' functions"
                ],
                "uri": "js/dist/makegrid.js?v=5.2.1deb1%2Bfocal2",
                "scriptname": "js/dist/makegrid.js"
            },
            {
                "func": "Object.hideEditCell",
                "line": "635",
                "column": "13",
                "context": [
                    "      if (g.isCellEditActive && !force) {",
                    "        // cell is being edited, save or post the edited data",
                    "        if (options !== undefined) {",
                    "          g.saveOrPostEditedCell(options);",
                    "        } else {",
                    "          g.saveOrPostEditedCell();",
                    "        }",
                    "        return;",
                    "      }",
                    "",
                    "      // cancel any previous request"
                ],
                "uri": "js/dist/makegrid.js?v=5.2.1deb1%2Bfocal2",
                "scriptname": "js/dist/makegrid.js"
            },
            {
                "func": "HTMLHtmlElement.<anonymous>",
                "line": "2032",
                "column": "13",
                "context": [
                    "        }",
                    "      });",
                    "      $('html').on('click', function (e) {",
                    "        // hide edit cell if the click is not fromDat edit area",
                    "        if ($(e.target).parents().index($(g.cEdit)) === -1 && !$(e.target).//...",
                    "          g.hideEditCell();",
                    "        }",
                    "      }).on('keydown', function (e) {",
                    "        if (e.which === 27 && g.isCellEditActive) {",
                    "          // cancel on pressing \"Esc\"",
                    "          g.hideEditCell(true);"
                ],
                "uri": "js/dist/makegrid.js?v=5.2.1deb1%2Bfocal2",
                "scriptname": "js/dist/makegrid.js"
            },
            {
                "func": "HTMLHtmlElement.newFunc",
                "line": "229",
                "column": "23",
                "context": [
                    "   */",
                    "  wrapFunction: function (func) {",
                    "    if (!func.wrapped) {",
                    "      var newFunc = function () {",
                    "        try {",
                    "          return func.apply(this, arguments);",
                    "        } catch (x) {",
                    "          TraceKit.report(x);",
                    "        }",
                    "      };",
                    "      newFunc.wrapped = true;"
                ],
                "uri": "js/dist/error_report.js?v=5.2.1deb1%2Bfocal2",
                "scriptname": "js/dist/error_report.js"
            },
            {
                "func": "HTMLHtmlElement.dispatch",
                "line": "3",
                "column": "3086",
                "context": [
                    "(function(global,factory){\"use strict\";if(typeof module===\"object\"&&typeof //...",
                    "if((elem=matcherOut[i])&&(temp=postFinder?indexOf(seed,elem):preMap[i])>-1)//...",
                    "continue}special=jQuery.event.special[type]||{};type=(selector?special.dele//...",
                    "var tween=this.createTween(prop,value);adjustCSS(tween.elem,prop,rcssNum.ex//...",
                    "jQuery.globalEval(text);return text}}});jQuery.ajaxPrefilter(\"script\",funct//...",
                    ""
                ],
                "uri": "js/vendor/jquery/jquery.min.js?v=5.2.1deb1%2Bfocal2",
                "scriptname": "js/vendor/jquery/jquery.min.js"
            },
            {
                "func": "elemData.handle",
                "line": "2",
                "column": "31779",
                "context": [
                    "(function(global,factory){\"use strict\";if(typeof module===\"object\"&&typeof //...",
                    "if((elem=matcherOut[i])&&(temp=postFinder?indexOf(seed,elem):preMap[i])>-1)//...",
                    "continue}special=jQuery.event.special[type]||{};type=(selector?special.dele//...",
                    "var tween=this.createTween(prop,value);adjustCSS(tween.elem,prop,rcssNum.ex//...",
                    "jQuery.globalEval(text);return text}}});jQuery.ajaxPrefilter(\"script\",funct//...",
                    ""
                ],
                "uri": "js/vendor/jquery/jquery.min.js?v=5.2.1deb1%2Bfocal2",
                "scriptname": "js/vendor/jquery/jquery.min.js"
            }
        ],
        "incomplete": "false",
        "partial": "true",
        "uri": "index.php?route=%2Fsql&pos=0"
    }
}
1
  • 1
    SyntaxError: Unexpected end of JSON input is not MySQL but PHP error message - i.e. you have not provided the query to MySQL even... Commented May 4 at 18:48

1 Answer 1

0

If a string in your JSON document contains literal double-quotes, you have to escape them. You did this with single backslash.

But backslash is itself an escape character in a MySQL string literal. You need a literal backslash in the JSON document, so you need to escape each backslash with a second backslash.

Demo:

SELECT JSON_VALID('[
    "ajaxPrefilter(\"script\",..."
]') as json_valid

+------------+
| json_valid |
+------------+
|          0 |
+------------+
1 row in set (0.00 sec)

SELECT JSON_VALID('[
    "ajaxPrefilter(\\"script\\",..."
]') as json_valid

+------------+
| json_valid |
+------------+
|          1 |
+------------+
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.