Giter VIP home page Giter VIP logo

convert-phpmyadmin-json-export's Introduction

convert-phpmyadmin-json-export

Script that re-writes a JSON export from phpMyAdmin so that numeric fields are not strings. For example, it takes the JSON export of:

[{ "type":"table","name":"myuser","database":"mysql", "data": [
   {"id": "3","firstName":"john","password":null,"maybeAFloat":"86.2"},
   {"id": "4","firstName":"mary","password":"*FF80A76950918AA85","maybeAFloat":"192.168.1.1"}]
 }]

yields the output of (with some whitespace removed):

[{"type": "table", "name": "myuser", "data":
    [{"id": 3, "firstName": "john", "password": null, "maybeAFloat": 86.2, },
     {"id": 4, "firstName": "mary", "password": "*FF80A76950918AA85", "maybeAFloat": "192.168.1.1",}]
}]

Notice the values of 3, 4, 86.2 and null are not strings, yet 192.168.1.1 remains a string. The main benefit here is that the numeric fields are output as Javascript numerics and not strings. If used to import to something like Firestore, the values will maintain their Javascript datatype, not simply all being stored as strings.

Trying It Out

  1. Clone this repository to your machine. For example:
    • git clone https://github.com/gregfenton/convert-phpmyadmin-json-export
  2. Go to the demo phpMyAdmin site, log in as user: root pass: (no password)
  3. At the top of the window, click Export
  4. Set:
    • Export method: quick
    • Format: JSON
  5. Click Go
  6. You just downloaded a JSON file. Copy it to the same directory that convertPhpJsonExport.js is in.
  7. Rename the JSON file so that its extension is .js. For example:
    • mv 192_168_30_23.json 192_168_30_23.js
  8. Edit the JSON file by adding the following as the first line of the file:
    • exports.mysqlData =     
  9. In the file convertPhpJsonExport.js, for the line that sets the jsonData variable, load the downloaded JSON data. For example:
    • var jsonData = require("./192_168_30_23").mysqlData;     
  10. Run the code in this script:
    • node convertPhpJsonExport.js > convertedOutput.json

Debugging

By default, debug logging is turned off. You can enable it, simply modify the line: const doLog = false; to const doLog = true;

Using Your Own phpMyAdmin JSON export

Follow steps 7 thru 10 using your own export .json file.

convert-phpmyadmin-json-export's People

Contributors

gregfenton avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.