parse json data in template Google App engine python - json

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?

Related

How can I query JSON of an XML parsing in a client only app?

Sorry for the inappropriate question. But what do you recommend me to use to structure a library that can put a query arrangement on json formats generated by an XML parsing based on TEI p5? I tried to use GraphQL by converting the interfaces of my Angular application related to parsing information from XML to JSON in type to define a GraphQL schema but I don't think that's the way.
What I have to do is query, client only, some data encoded in XML (also wanting already parsed in JSON) and, for example, search for all occurrences of a specific data.
Do you have any roadmaps to recommend or some JSON query system that might be right for me?
You might take a look at https://www.npmjs.com/package/saxon-js. With SaxonJS you're able to run XPath expression against XML using JavaScript.

Querying Contentful local JSON results in JavaScript client side?

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.

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.

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.

HTML::Template Perl

IIs there a package similar to HTml::Template in perl which takes a JSON object and maps it to a HTML template file? I am building a web application using HTML::Template and will be receiving JSOn from a web services API, things will be made simple if I can templatize this JSOn to HTML instead of doing it the exact way HTML::Template requires.
HTML::Template just takes a data structure consisting of strings, hashes and arrays. JSON maps directly onto that.
$template->param(myData => JSON::Any->new->decode($json_string));
HTML::Template is a rather 'simple' templating engine - I am using quotes because its simplicity let's you do whatever you need in a view part from the Model View Controller architecture.
However, you can not execute arbitrary perl code inside a HTML::Template.
Also, due to the fact that in JSON you could have very complex data structures, I doubt that there are any suitable ways of using JSON in a straight way in your templates.
The only solution I see as possible is for you to use a Perl script that will parse the JSON, create some 'objects' and pass them to your templates. You already have that perl script - is the one that instantiate your HTML::Template object.
ok, a bit late, but:
HTML::Template always wants a hash of arrays of hashes and so on.
and you cannot navigate through the parameter stash.
If you want to do this, you might try out HTML::Template::Compiled which allows you to do this.
<tmpl_var some_hash.key.another_key[23] >
or with alternative delimiters:
[%= some_hash.key.another_key[23] %]
but note the documented differences of the module to HTML::Template.
So you decode your JSON string to a data structure and pass it to the template and then you can access all values somewhere deep in the structure.