Querying Contentful local JSON results in JavaScript client side? - json

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.

Related

Create JSON Object in React.js from Rest Service

I am looking for either guidance or a good example where I can map data coming from rest services to JSON "type" object which can then be used in a number of different react components.
The JSON Object will be used to map data from a few different rest services, which essentially hold very similar data which makes it better to use one object and then to bind the data to the respective React Components.
I am fairly new to React.JS and I have googled around to find a data mapper to JSON from Rest Service example.
Can anyone help?
You typically don't have to do too much, at least on the front end side. As long as the REST endpoint can return JSON responses you'll be fine. Just make sure you set the appropriate Content-Type headers in the request. Note that setting the header doesn't guarantee a JSON response, the server has to be able to send it in that format.
If you're creating the REST service yourself, you have many options. If you're using node, you can simply return a javascript object. If you're using some other language like Java, C#, etc., they come with libraries that can serialize objects into JSON for you. I use JSON.net when working with C#. In these cases, because the data will be returned as a string, you'll just need to JSON.parse() it upon receiving it and then set it to the appropriate React component's state.

How do i get JSON data from a couchDB database and parse it in Xcode?

For Example,
I have a document in my CouchDB database that holds two fields
"password" and "username".
This is the URL for my document:http://127.0.0.1:5984/_utils/document.html?sgram/fdcfc14940fbaa0d86674046ce005107
I want to retrieve the value of these fields from that specific document in CouchDB and parse it in Xcode.
I tried using http-get but it just returns the entire page source.
You want to make a request to this endpoint
http://127.0.0.1:5984/sgram/fdcfc14940fbaa0d86674046ce005107
For a json response from couchdb just don't include _utils/document.html in between. If you do it will give you back the futon html page.

Turn Json file API into MySQL data table

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.

How to query ASP.NET Web API like OData, but with a POSTed JSON object, not a GET URL/QueryString?

How to query ASP.NET Web API, but with a JSON POST, not GET URL?
The JSON object would contain the same data/filters/sort/paging as ODATA query or LINQ query. Can we deserialize the JSON object into something ODATA/LINQ can understand and then use that to easily execute on the DB (SQL Server)?
We've come across from articles about LINQ Expression Trees and ODataLib ODataUriParser, but still researching.
We want to expose an advanced search web service for a few tables or views in SQL Server, and want to keep it JSON and generic so many platforms can consume it. The consumer would need to pass in the search parameters, and we could probably create a data structure to contain it all, but are trying to also see if we can leverage some query model in ODATA or LINQ.
Any way to instead of putting the OData query in the URL, put it as a POSTed JSON object instead and have it continue to query the DB and return results normally? A couple of current reasons to put in POST are 1. can handle larger size and 2. instead of the consumer learning OData query syntax, they can just popular an search param object model.
Thanks in advance.

parse json data in template Google App engine python

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?