Skip to content

primaryobjects/json-to-sqlite

Repository files navigation

json-to-sqlite

Convert a JSON file to an SQLite database right from VSCode!

Install in VSCode.

Screenshot

Quick Start

  1. Open your VSCode project.
  2. Right-click a JSON file such as example.json.
  3. Select the context menu Convert JSON to SQLite.
  4. A new file example.sqlite will be saved in the same directory. The database table name is the same as the filename example.

To preview an SQLite file contents:

  1. Right-click a SQLite file such as example.sqlite.
  2. Select the context menu Preview SQLite File.
  3. A message will display showing the top 3 records in the database.

Settings

To change the name of the table saved in the sqlite file, use the following steps.

  1. In VSCode, select File->Preferences->Settings.
  2. Search for json-to-sqlite.
  3. Enter a value for Custom Table Name.
  4. Uncheck the option Use Filename As Table Name.

Features

  • Convert any JSON file to SQLite.
  • Right-click a JSON file or use the command pallete Ctrl-Shift-P->Convert JSON to SQLite and choose a file.
  • Preview SQLite file contents.
  • Customize the table name stored in sqlite.

JSON Formats

The following JSON file formats are supported for conversion to SQLite:

Single Table Format Array

This results in a single table with the name of the JSON file or as configured in settings.

[
  {
    "id": 1,
    "first_name": "Loella",
    "last_name": "Albers"
  },
  {
    "id": 2,
    "first_name": "Laurie",
    "last_name": "Strongman"
  }
]

Named Table Format

This results in a single table with the name "locations".

{
  "locations": [
    {
      "id": 0,
      "name": "Acme Fresh Start Housing",
      "city": "Chicago",
      "state": "IL"
    },
    {
      "id": 1,
      "name": "A113 Transitional Housing",
      "city": "Santa Monica",
      "state": "CA"
    }
  ]
}

Multiple Named Table Format

This results in two tables with the names "table1" and "table2".

[
  {
    "table1": [
      {
        "id": 0,
        "name": "Acme Fresh Start Housing",
        "city": "Chicago",
        "state": "IL"
      },
      {
        "id": 1,
        "name": "A113 Transitional Housing",
        "city": "Santa Monica",
        "state": "CA"
      }
    ]
  },
  {
    "table2": [
      {
        "id": 0,
        "name": "Acme Fresh Start Housing",
        "city": "Chicago",
        "state": "IL"
      },
      {
        "id": 1,
        "name": "A113 Transitional Housing",
        "city": "Santa Monica",
        "state": "CA"
      }
    ]
  }
]

Deployment

To deploy and publish the extension, use the following steps.

  1. Open a VS Code terminal window and use the command: vsce package
  2. In VS Code, open the Extensions tab and click '...' in the top-right and choose Install from VSIX.
  3. Select to install the newly packaged .vsix file created in step 1.
  4. Test the extension.
  5. Upload the package to the marketplace.

License

MIT

Author

Kory Becker http://www.primaryobjects.com/kory-becker

Packages

No packages published

Contributors 2

  •  
  •