question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide an option to disable JSON parsing

See original GitHub issue

In both binary_parser.js and text_parser.js we’re parsing the JSON string to a native object:

case Types.JSON:
  // Since for JSON columns mysql always returns charset 63 (BINARY),
  // we have to handle it according to JSON specs and use "utf8",
  // see https://github.com/sidorares/node-mysql2/issues/409
  return 'JSON.parse(packet.readLengthCodedString("utf8"))';

Similarly to the configuration option dateStrings, it would be nice to provide something like jsonStrings which would avoid this and just return the utf8 string.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
OrkhanAlikhanovcommented, Jan 29, 2022

I need to disable this as well. It’s for perf reasons. Also mysql package has this disabled (probably not implemented at all). Switching to mysql2 was not smooth for me because of this feature. I’d be happy to see option to disable this

1reaction
bunchjessecommented, Nov 27, 2019

Yeah, here is what I settled on to get unblocked (in case anyone else finds it helpful):

async function performWithTypeCastsDisabled(ctx: AppContext, fn: () => Promise<any>) {
  const oldTypeCast = ctx.db.client.connectionSettings.typeCast;
  const oldDateStrings = ctx.db.client.connectionSettings.dateStrings;
  // Provide a custom typeCast functionm that disables JSON parsing
  // See https://github.com/sidorares/node-mysql2/issues/1072
  ctx.db.client.connectionSettings.typeCast = function (field: any, next: any, packet: any) {
    if (field.type === "JSON") {
      return field.string();
    } else {
      return next();
    }
  }
  // Disable parsing to date object because this causes the format
  // to change and it isn't directly re-importable after.
  ctx.db.client.connectionSettings.dateStrings = true;
  await ctx.db.destroy();
  await ctx.db.initialize();
  await fn();
  ctx.db.client.connectionSettings.typeCast = oldTypeCast;
  ctx.db.client.connectionSettings.dateStrings = oldDateStrings;
  await ctx.db.destroy();
  return ctx.db.initialize();
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable JSON parsing in Axios - Stack Overflow
This works fine for everything except JSON files, which are automatically parsed and therefore not available as a String, but as a javascript ......
Read more >
How to Disable JSON REST API in WordPress - WPBeginner
Disabling JSON REST API in WordPress with Code (Recommended) We recommend using the WPCode plugin to disable JSON REST API in WordPress. WPCode ......
Read more >
How to Ignore Unknown Properties While Parsing JSON in ...
That's all about how to ignore unknown properties while parsing JSON in Java using Jackson API. You can do this either by using...
Read more >
Parse JSon schema box is disable - Power Platform Community
Parse JSon schema box is disable. Reply. Topic Options ... into a SharePoint list using JSON but when I'm building the Parse JSON...
Read more >
Options | Swagger Parser - API Dev Tools
To disable a parser, just set it to false . json.order yaml.order text.order binary.order, number, Parsers run in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found