I'm doing an app with angular since it's easy for me to make it work as a progressive web app, etc. In my app I have a blog section.
The problem is that I need to load a json files dynamically because I'm using it to make new post pages as entry blogs.
I need to know if i can create something like a folder named json and throw all my json files with the content of each post, keeping the angular parsing the folder and looking for new jsons while it's in run time. Or i must use a backend with some mongo or mysql bbdd?
You need to use backend to implement.
Try to receive the service response in JSON array as below:
{
"posts": [
{
"author": "Chinua Achebe",
"content": "abc"
},
{
"author": "Hans Christian Andersen",
"content": "def"
}
]
}
Just iterate over the posts array to display your posts
Related
I am working on an Angular application (using Angular 9) to build out a website that has articles written by my organization. I would be publishing the articles on my own time after reviewing their emailed submissions to me. I am thinking of using JSON files for each article, structured as such:
[
{
"id": 1,
"title": "Test Title",
"author": "Test Author",
"disclaimer": "Test Disclaimer",
"body": "Test Body"
}
]
I am not sure if the id field is necessary but I saw it being used on a lot of JSON/Angular demos online so I thought I would include it as a unique identifier to each JSON file. Does anyone have any resources on how I can take these JSON files to create and format articles for my website? Any links to examples and resources would be helpful. I have been trying to find some but have had no luck. Thank you.
Well it up to you what all things you need to display. Your format looks good.
According to me following things need to maintained
Unique id
Title
author
Article itself
votes(if you are maintaining)
dateCreated
But any other schema will work as it varies application to application
I am creating a local weather web app by applying data from openweathermap api.
THe instructions for openweathermap api recommend to use cityId to query the endpoint and get data for a specific city. The cityId's are stated to be found in a json file that can be downloaded from this link: weathermap api json
Each object in the json looks like this:
{
"id": 707860,
"name": "Hurzuf",
"country": "UA",
"coord": {
"lon": 34.283333,
"lat": 44.549999
}
},
{
"id": 519188,
"name": "Novinki",
"country": "RU",
"coord": {
"lon": 37.666668,
"lat": 55.683334
}
},
I first downloaded this json file and placed it in my project but it slows its performance down quite a bit so I did some research and thought that my best answer was creating a citylist table in postgresql where each city has an id and a jsonb column that would simply be a parsed city object from the json file.
My problem is I don't know how to load each object in the json to the postgres db without manually writing insert sql queries for each object.
What is the most efficient way to load this json file into postgres? Do i need to export the json from it's file and write a script in my project that imports the json, parses each object and converts it into a sql query string? That doesn't sound efficient and my gut tells me there's an easier way.
Suggestions on how to do this with postgres or any other approach would be appreciated.
I'm new to Grails, and I'm stuck on the basic structure of my web-app
So far I've implemented a Grails app that renders one JSON file to a readable table.
example
Given JSON file below
{
"abbreviation": "EXAMPLE",
"guid": "31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03",
"metadata": {
"dataOrigin": "Example"
},
"rooms":
[
],
"site": {
"guid": "31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03"
"title": "Example Testing"
}
}
My app renders above JSON file to below
Abbreviation : Example
GUID : 31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03
Metadata : - DataOrigin : Example
Rooms : []
Site - GUID : 31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03
Title : Exmaple Testing
Now, what should I do if I want my app to read JSON files with different Name/value pairs and renders it similarly to what my app does now?
(I've hard coded the application I have now)
I know this question is very vague, but can anyone give me any directions or insights on how to do this?
I'm afraid if there was a simply answer to this question then half of the web developers would be out of their jobs :-)
Anyway, there's probably several steps that could help in achieving your goal.
JSONSlurper(http://docs.groovy-lang.org/latest/html/gapi/groovy/json/JsonSlurper.html) to read JSON files. Obviously if you go for predefined structures you could use GSON (https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/Gson.html) or similar library.
To display arbitrary data you can use the Grails Fields plugin(https://grails.org/plugin/fields).
I know it's all only pointers.
I developed a web service that extracts messages from a database and returns an object containing a table and a string, as a json response.
The problem is that I can't extract data from the client application when I consume the web service.
This is the reponse I get when I run the web service
{
"msgTabl":
{
"list":
[
{"contenu":"aid mabroukk","dateEnvoi":"2014-07-30","frommm":"voeuxmsg","id":0,"idu":0,"numExp":50840749},
{"contenu":222222222222,"dateEnvoi":222222,"frommm":222222222222,"id":0,"idu":0,"numExp":2222222},
{"contenu":3333333333,"dateEnvoi":3333333333,"frommm":333333333,"id":0,"idu":0,"numExp":33333333333}
],
"test":"ok"
}
}
I tried to take the json content from my client application, but I couldn't because of the structure of my json reponse. I don't know why this "msgTabl" is shown at the beginning.
You can use
reponse['msgTabl']
in your client application to get the right structure you want
I would be wanting a tool which can mock a RESTFul server and it should return the preset JSON data which I have mapped for a particular URL.
For ex: If I call http://ccccc.com/api/users , the mockup tool should return users ( which I have already preset ) in JSON format.
This might be useful when I create client side code with backbone or jquery to get back the models using an ajax call.
Any suggestions for this kind of mockup tool ?
Note: Creating a servlet which reads the incoming GET url and reads the preset JSON from a file and outputting it as JSON string is possible. But I am looking for a tool which will do this for me.
Sinon.js is what you're looking for. In particular the sinon.fakeServer API.
https://github.com/homerquan/kakuen
Mock up RESTful webservices simply by editing text files, e.g.,
GET_#book#123#authors.json ==> GET /book/123/authors
POST_#book#id=123.json ==> POST /book?id=123
For json, a schema-based mockup is supported, e.g., in sample_server/mocks/GET__#search#q=js.json
e.g.,
"#KAKUEN_ITEM(offset)": {
"#KAKUEN_TYPE": "natural",
"#KAKUEN_PARAM": {
"min": 1,
"max": 20
}
}
will be offset:12