I'd like to know if it's possible to turn a Json file API like this one :
http://graph.facebook.com/10152830671619648/photos?fields=id,name,source
to a MySQL data table in a database.
What language shall I use for this ? PHP, Javascript ?
Thanks for answering !
EDIT : Actually, I'd like to create a system to manage the comics I need to buy with a simple interface. All the information about a comic book will be stored in a database (id, name, image link, if I need it, if I have it, if I read it).
In PHP, there are several ways to get the JSON object from url including fopen, get_file_contents and curl, the latter being the more reliable option if there are restrictions on the server.
JSON url to PHP object:
- Get JSON object from URL
Serialize and store to db:
- How do I store an php object in a MySQL table?
or write object properties to db table columns:
- mysqli: http://php.net/manual/en/mysqli-stmt.bind-param.php pdo:
- http://php.net/manual/en/pdostatement.bindparam.php
JavaScript can be used as well, using Ajax to both retrieve the JSON object and to store it in the db e.g. by sending it to a server-side script which do the storing. You can use PHP, PHP and JavaScript (Ajax), JavaScript and some JavaScript Ajax APIs, etc.
Related
I'm working on flutter mobile application which should be attached (connected) with the web platform that I developed with laravel, I want to generate JSON file from Postgres dynamically , I mean when I update any thing in the database it will be updated in the mobile also and I need to display the data in the mobile application.
I followed this tutorial and I understood that I must convert the database or the tables into json file. How I'm going to do it please, it's the first time I'm working with Flutter and json.
https://www.youtube.com/watch?v=m7b7_Nq7XSs&list=PLK7ZDJTUghFAmRR4mueiai7zq1RJfMQ62&index=11&t=1s
If you're just getting started, please take your time and get yourself familiar with the basics and how flutter treats the data coming from a database.
Also something you should have been reading and understood is JSON and serialization.
Based on that it is not advisable that you retrieve JSON right from the database. Instead, JSON serialization happens in one way or another inside flutter using one of the recommended approaches.
Specifically for working with PostgreSQL, there seems to be a decent tutorial.
Please keep in mind that what you actually have asked for here ("... database to JSON file") indicates you really want a file output, which is completely contrary to the API that you're going to provide with flutter.
Of course it is possible to query PostgreSQL and get the result already in JSON format, but that then also means you won't be able to work with the data model inside flutter.
However, if you finally know what you are doing, here is a way to get the result of any PostgreSQL query directly as JSON:
SELECT json_agg(t) FROM (
SELECT ...whatever you can think of...
) AS t;
If you are using laravel version greater than 5, you can use API resources to create API and connection to PostgreSQL(https://laravel.com/docs/5.7/database). It is so simple to create API using laravel API resources. Then in Flutter only thing you have to do is request endpoints you have created using laravel.
I am using Contentful CMS - when my JavaScript app loads, I retrieve all the articles/entries during app initialization. I then want to query this local json object without doing futher Http calls to Contentful
Each entry of the 'items' array will have 'id' links to categories/authors/assets etc which will be in the returned Json.
Is there a JavaScript library or API I can use to query this Contentful json data locally on the client side?
You probably want to look at normalizr for that. The idea is to transform JSON into something that you can access by entity type + entity id, so it 'feels' more like querying a relational database.
I have WordpressTheme and in my MySql Database is Stored a Value like the following.
Its an Optionlist that shows up in an Form, but I never saw something like this.
Any Ideas what this is and how to handle with it?
Or where do find a Documentation about it.
a:9:{i:0;a:4:{s:8:"cssClass";s:8:"textarea";s:8:"required";s:9:"undefined";s:6:"values";s:53:"Script (Copy Paste your Script here or Upload a File)";
That is a string representing a serialized PHP object.
You can get more information about PHP serialization on http://php.net/manual/function.serialize.php
Wordpress and some plugins use PHP serialization to store some internal settings in a database easily.
That's the result of PHP serialize(). You can decode it with unserialize().
I am storing json data in the database in my google app engine, There is no problem in stroing the data to DB, But I am not sure how to parse it in the view, For e.g I get all the topics from my MODEL and pass it to the view which is using webapps template (I am not sure its django or jinja2 but it is the default provided by GAE), now my Model objext has one atribute which contains json, I want to parse this json in view without javascript as I am passing the object via template, can any one suggest me how to do it.
for e.g. I query the app engine as
topics = Topic.all()
//topic have many attributes including an attribute tags which contains json string
//["test", "somekeyword"]
I parse this string as individual tags in my view, Can I manipulate this list of objects in python to store as disctionary instead of tags when I retrieve it ? or is there a way to convert it to dictionary in django ?
P.S: I cant parse the json in my handler as the model will have multiple entries and parsing and storing these entries will be difficult
The webapp template language is Django (by default a rather old version). I think you have to change your requirements -- you can parse JSON in Python or in Javascript, but the Django template language is (intentionally) too weak to do that. Maybe show us some samples of the data you want to work with?
It seems that Yahoo pipes are represented using JSON. I want to download these JSON objects for some research purpose. Usually a Yahoo pipe is rendered in a browser editor thru a url like this: http://pipes.yahoo.com/pipes/pipe.edit?_id=XgRo96h13BGtJWvS8SvLAg, but you can't get the corresponding JSON object to this Yahoo pipe. Does anyone know how to get JSON objects representing Yahoo pipes and store them in any persistent form?
It is possible to get hold of a JSON description of a Yahoo Pipe using a URL of the form:
http://pipes.yahoo.com/pipes/pipe.info?_out=json&_id=PIPE_ID
The pipe2py python library demonstrates how to grab the JSON description of a pipe and "compile" it to a Python equivalent that can be run on your own server.
The post Exporting Yahoo Pipe Definitions, Compiling Them to Python, and Running Them in Scraperwiki describes how you can use pipe2py in the Scraperwiki environment to compile and execute pipes on Scraperwiki using pipe definitions imported directly from Yahoo Pipes, or exported from Yahoo Pipes and then stored locally in a Scraperwiki database table.
When I load that page in a browser I can see that it makes an ajax request for:
http://pipes.yahoo.com/pipes/ajax.pipe.load?id=XgRo96h13BGtJWvS8SvLAg&_out=json&modinfo=true&rnd=7560&.crumb=MjvGjpzhPLl
That's your object but I'm not sure if I'm answering your question of how to "get it". If you need to get it through a program you would need a script that loges into pipes and extracts that url.
A quick way, while not automated, is to use an HTTP analyzer. Here's a process for getting the object using HttpFox (I use v0.8.9) for Firefox. With the analyzer running, load the edit page for a pipe, like the one you linked:
http://pipes.yahoo.com/pipes/pipe.edit?_id=XgRo96h13BGtJWvS8SvLAg
Look at the request with a URL that starts with:
http://pipes.yahoo.com/pipes/ajax.pipe.load?id=....
Next, explore the content of the request (there's a 'Content' tab in HttpFox). That's the JSON object representing the pipe structure.
Use pipe.run?[your pipe id here]&_render=json as opposed to pipe.edit
So in your case to get the json it would be - http://pipes.yahoo.com/pipes/pipe.run?_id=XgRo96h13BGtJWvS8SvLAg&_render=json
I guess how you implement the client is dependent on what you like writing in/what other functionality you need.
You could also do it the other way around and use the web service service module to post the data to a script that can extract the json and persist it to a database. You could check out json.org.