adamwulf / json-to-mysql Goto Github PK
View Code? Open in Web Editor NEWEasily take any JSON object and create+insert it into a mysql table built from its structure. Also search, update, index, and validate tables with JSON.
License: Other
Easily take any JSON object and create+insert it into a mysql table built from its structure. Also search, update, index, and validate tables with JSON.
License: Other
when I run:
$ php example.php
I get:
PHP Notice: Undefined variable: classLoader in /home/sbash/json-to-mysql/example.php on line 10
PHP Fatal error: Call to a member function addToClasspath() on null in /home/sbash/json-to-mysql/example.php on line 10
I only edited the file to add <?php as short tags do not work in my environment. I get this on php 7.x and 5.6...
I have tested this on a clean 'git clone ...' just making the short tag modification above to no avail...
Many PHP environments come such as XAMPP are pre-configured to ignore PHP short tags (<?
), better use the ones that work everywhere (<?php
)
How to receive subdata Events?
{ "CommandStatus": "0", "Events": [ { "ActivityId": "1" },{ "ActivityId": "2" },...,{ "ActivityId": "867" } ], "EventsCount": "867" }
/JSONtoMYSQL/lib/class.MySQLConn.php creates an instance of DatabaseException but there is no such class in the repo.
Importing JSON with multiple sub-arrays nested to different depths fails with 'need to handle sub-array's' message.
This way the dev has the option to validate an object to a table, which'll add fields to the table, or validate the object against the table, which'll remove fields from the object
While i am processing my json data .Iam getting "need to handle array subdata" error is coming ..
The example given works beautifully - however, when adding the same JSON data, the $db->save(...) method creates a duplicate in the resulting table. Is it possible to check for the row first and avoid duplicated entries - ie. if (!$db->find($json_object,"table") ...?
If someone could "flesh out" the example to include any other functions (search, update...), it would be hugely appreciated.
Hi there,
I just wanted to do a quick test under windows, and your path separators won't work here. You might want to use DIRECTORY_SEPARATOR instead of "/" in the future, to build your strings.
Try to auto-create indexes on columns based on the JSON data that populates the table, and based on the searches on a table. If a table is consistently searched on its start_date
column, then auto-add an index on that column. Same for multi-column indexes.
Please add composer installation instructions to Readme.md
bug in code
Line 208 in ExistingMYSQLTable.php should use variable $val
instead of $value
. You do not iterate with the correct element used.
Your example in README.md has a typo
$obj = $db->table("brandnewtable")->find(["id" => [4, 5, 6 7]]);
should be
$obj = $db->table("brandnewtable")->find(["id" => [4, 5, 6, 7]]);
note the missing comma.
when creating new tables, allow creation of a custom primary key, including custom type. i assume its possible for a custom primary key of varchar (?) or text (?).
I am getting a NULL value from the class, but all files are found.
The return JSON object is fully populated with data.
Enter the Object ID you would like for me to retrieve 'hearts' for.
Given a JSON object, validate the construction of a mysql table, including sub-tables, foreign keys, and data types. Return a JSON object describing what edits should be made (new columns, change types, add NULLABLE, etc) to the existing table if any
Hi there,
I'm parsing data from the youtube API. In this case I got an array of items I'd like to parse:
this is the input for the json_decode
String input for json_decode:
'{
"title": "Dave Gaming",
"description": "Willkommen zu meinem Channel mit der besten Community weit und breit! \n\nHier findet ihr alles, was das Gamerherz begehrt. 20 Jahre alt und seit 17 Jahren leidenschaftlicher Gamer!\n \nGespielt wird alles, was Spaß macht:\n\nAktuell:\n- F1 2015 - GTA ONLINE - League of Legends - MAD MAX - FIFA 16 - Tearaway Unfolded - Forza 6 - SOMA\n\nKommende Let's Plays:\n\n\nOKTOBER:\nUncharted Collection - Assassin's Creed: Syndicate - HALO 5\n\nNOVEMBER:\nNeed for Speed - Call of Duty: Black Ops 3 - Rise of the Tomb Raider - Star Wars: Battlefront 3\n\nDEZEMBER:\nJust Cause 3\n \n \nAuf eine geile gemeinsame Zeit! :)",
"publishedAt": "2014-10-17T21:04:42.000Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/-80u0cN0eJrY/AAAAAAAAAAI/AAAAAAAAAAA/y5b34eyGCrM/s88-c-k-no/photo.jpg"
},
"medium": {
"url": "https://yt3.ggpht.com/-80u0cN0eJrY/AAAAAAAAAAI/AAAAAAAAAAA/y5b34eyGCrM/s240-c-k-no/photo.jpg"
},
"high": {
"url": "https://yt3.ggpht.com/-80u0cN0eJrY/AAAAAAAAAAI/AAAAAAAAAAA/y5b34eyGCrM/s240-c-k-no/photo.jpg"
}
},
"localized": {
"title": "Dave Gaming",
"description": "Willkommen zu meinem Channel mit der besten Community weit und breit! \n\nHier findet ihr alles, was das Gamerherz begehrt. 20 Jahre alt und seit 17 Jahren leidenschaftlicher Gamer!\n \nGespielt wird alles, was Spaß macht:\n\nAktuell:\n- F1 2015 - GTA ONLINE - League of Legends - MAD MAX - FIFA 16 - Tearaway Unfolded - Forza 6 - SOMA\n\nKommende Let's Plays:\n\n\nOKTOBER:\nUncharted Collection - Assassin's Creed: Syndicate - HALO 5\n\nNOVEMBER:\nNeed for Speed - Call of Duty: Black Ops 3 - Rise of the Tomb Raider - Star Wars: Battlefront 3\n\nDEZEMBER:\nJust Cause 3\n \n \nAuf eine geile gemeinsame Zeit! :"
},
"country": "DE"
}'
output of json_decode():
stdClass Object ( [title] => Dave Gaming [description] => Willkommen zu meinem Channel mit der besten Community weit und breit! Hier findet ihr alles, was das Gamerherz begehrt. 20 Jahre alt und seit 17 Jahren leidenschaftlicher Gamer! Gespielt wird alles, was Spaß macht: Aktuell: - F1 2015 - GTA ONLINE - League of Legends - MAD MAX - FIFA 16 - Tearaway Unfolded - Forza 6 - SOMA Kommende Let's Plays: OKTOBER: Uncharted Collection - Assassin's Creed: Syndicate - HALO 5 NOVEMBER: Need for Speed - Call of Duty: Black Ops 3 - Rise of the Tomb Raider - Star Wars: Battlefront 3 DEZEMBER: Just Cause 3 Auf eine geile gemeinsame Zeit! :) [publishedAt] => 2014-10-17T21:04:42.000Z [thumbnails] => stdClass Object ( [default] => stdClass Object ( [url] => https://yt3.ggpht.com/-80u0cN0eJrY/AAAAAAAAAAI/AAAAAAAAAAA/y5b34eyGCrM/s88-c-k-no/photo.jpg ) [medium] => stdClass Object ( [url] => https://yt3.ggpht.com/-80u0cN0eJrY/AAAAAAAAAAI/AAAAAAAAAAA/y5b34eyGCrM/s240-c-k-no/photo.jpg ) [high] => stdClass Object ( [url] => https://yt3.ggpht.com/-80u0cN0eJrY/AAAAAAAAAAI/AAAAAAAAAAA/y5b34eyGCrM/s240-c-k-no/photo.jpg ) ) [localized] => stdClass Object ( [title] => Dave Gaming [description] => Willkommen zu meinem Channel mit der besten Community weit und breit! Hier findet ihr alles, was das Gamerherz begehrt. 20 Jahre alt und seit 17 Jahren leidenschaftlicher Gamer! Gespielt wird alles, was Spaß macht: Aktuell: - F1 2015 - GTA ONLINE - League of Legends - MAD MAX - FIFA 16 - Tearaway Unfolded - Forza 6 - SOMA Kommende Let's Plays: OKTOBER: Uncharted Collection - Assassin's Creed: Syndicate - HALO 5 NOVEMBER: Need for Speed - Call of Duty: Black Ops 3 - Rise of the Tomb Raider - Star Wars: Battlefront 3 DEZEMBER: Just Cause 3 Auf eine geile gemeinsame Zeit! : ) [country] => DE )
when I call
$db->save($obj, "channel");
where will be only the fields:
id
title
description
publishedAt
country
Sub-Elements will currently be ignored without any warning.
It would be great if you could add/insert into another table for each sub element and handle the mapping.
easily search for data matching an input JSON object. figure out how to easily support wildcard text search, and < > for numeric and date columns
Greetings:
I'd really like the approach of this project, but I am unable to utilize it, at its present form.
It does have potentials, however, to make a GREAT Project!
I was looking for a way to import any JSON into an SQLite3, but this should work, just as well.
JSON that I am trying to import is like this:
{
"stations":[
{
"id":"WYNI1",
"name":"DALE BITNER",
"elev":"6391",
"latitude":"43.049722",
"longitude":"-111.379444",
"state":"ID",
"distance":"",
"provider":"RAWS",
"link":"http://www.wrh.noaa.gov/mesowest/getobext.php?sid=WYNI1",
"Date":"9:45 pm MDT Sep 26, 2014",
"Age":"0.55",
"Temp":"59",
"Dewp":"46",
"Relh":"63",
"Wind":"NW@8",
"Direction":"309°",
"Winds":"8",
"Windd":"309",
"Gust":"26",
"AccPrecip":"14.67",
"FuelMoist":"9.8",
"FuelTemp":"58",
"Ceiling":""},
{
"id":"690",
"name":"Central Facilities",
"elev":"4950",
"latitude":"43.5326",
"longitude":"-112.94775",
"state":"ID",
"distance":"",
"provider":"ARL FRD",
"link":"http://www.wrh.noaa.gov/mesowest/getobext.php?sid=690",
"Date":"10:00 pm MDT Sep 26, 2014",
"Age":"0.30",
"Temp":"57",
"Dewp":"53",
"Relh":"88",
"Wind":"E@12",
"Direction":"79.6°",
"Winds":"12",
"Windd":"79.6",
"Gust":"16",
"a5minPrecip":"0.00",
"Ceiling":""}]}
The idea is to take a json object, and insert auto-generate the table and/or columns necessary to insert the data into mysql.
given a json object and target table name:
if the JSON object contains other objects as its property values, then flatten them into columns, so:
{ "foo" : { "bar1" : "baz1", "bar2" : "baz2"} }
is equivalant to:
{"foo_bar1" : "baz1", "foo_bar2" : "baz2" }
if a property contains an array for a value, then each of those objects should be added to their own mysql table, with a foreign key to the original table's row. so:
{ "foo" : [{ "bar" : "baz1"}, {"bar" : "baz2"}] }
would auto generate a table tablename_foo
, with foreign key column: foo_id
that points to the original foo object. tablename_foo
would also contain the data column bar
, and 2 rows for each baz1
and baz2
would be inserted.
when inserting data into a table, allow it to have data in sub objects, and create normal keys in the original object for that data. so:
{ "properties" : { "one" : true, "two" : false} }
becomes:
{ "properties_one" : true, "properties_two" : false}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.