flutter REST API reading with nested JSON link - json

I'm integrating an API I found on Github and In the JSON data there is a link object which leads to another JSON file. this particular REST API structure is as follows.
{
"aar_sheikhmahmoudab": {
"name": "aar-sheikhmahmoudab",
"author": "Sheikh Mahmoud Abdel Qader Hamz And Group Of Scholars",
"language": "Afar",
"direction": "ltr",
"source": "https://qurancomplex.gov.sa/",
"comments": "This translation was OCRed, in case you find any mistakes,
"link": "https://cdn.jsdelivr.net/gh/fawazahmed0/quran-api#1/editions/aar-sheikhmahmoudab.json",
"linkmin": "https://cdn.jsdelivr.net/gh/fawazahmed0/quran-api#1/editions/aar-sheikhmahmoudab.min.json"
},
"ace_tgkhmahjiddinju": {
"name": "ace-tgkhmahjiddinju",
"author": "Tgk. H. Mahjiddin Jusuf",
"language": "Achinese",
"direction": "ltr",
"source": "https://www.islamic-invitation.com/",
"comments": "This translation was OCRed, in case you find any mistakes,
"link": "https://cdn.jsdelivr.net/gh/fawazahmed0/quran-api#1/editions/ace-tgkhmahjiddinju.json",
"linkmin": "https://cdn.jsdelivr.net/gh/fawazahmed0/quran-api#1/editions/ace-tgkhmahjiddinju.min.json"
},
}
and the link object leads to another JSON data
{
"quran": [
{
"chapter": 1,
"verse": 1,
"text": "«بسم الله الرحمن الرحيم»"
},
{
"chapter": 1,
"verse": 2,
"text": "«الحمد لله» جملة خبرية قصد بها الثناء على الله بمضمونها من أنه تعالى: مالك لجميع الحمد من الخلق أو مستحق لأن يحمدوه، والله علم على المعبود بحق «ربِّ العالمين» أي مالك جميع الخلق من الإنس والجن والملائكة والدواب وغيرهم، وكل منها يُطلق عليه عالم، يقال عالم الإنس وعالم الجن إلى غير ذلك، وغلب في جمعه بالياء والنون أولي العلم على غيرهم، وهو من العلامة لأنه علامة على موجده"
},
]
}
so my question is that how can I integrate a JSON inside another JSON in my app. any tutorial on this can help me a lot?

Related

Extracting structured data from web page using JSOUP and Coldfusion

I need to extract structured data for recipes from a website using JSOUP (or any other effective method) using Coldfusion.
The data is structure as follows: https://developers.google.com/search/docs/advanced/structured-data/recipe
I need to get the JSON from the page and parse it into useable variables.
I have tried a number of different options without success. I do not know JSOUP and will appreciate your help.
The data looks like this:
<script type="application/ld+json">
{
"#context": "https://schema.org/",
"#type": "Recipe",
"name": "Party Coffee Cake",
"image": [
"https://example.com/photos/1x1/photo.jpg",
"https://example.com/photos/4x3/photo.jpg",
"https://example.com/photos/16x9/photo.jpg"
],
"author": {
"#type": "Person",
"name": "Mary Stone"
},
"datePublished": "2018-03-10",
"description": "This coffee cake is awesome and perfect for parties.",
"prepTime": "PT20M",
"cookTime": "PT30M",
"totalTime": "PT50M",
"keywords": "cake for a party, coffee",
"recipeYield": "10",
"recipeCategory": "Dessert",
"recipeCuisine": "American",
"nutrition": {
"#type": "NutritionInformation",
"calories": "270 calories"
},
"recipeIngredient": [
"2 cups of flour",
"3/4 cup white sugar",
"2 teaspoons baking powder",
"1/2 teaspoon salt",
"1/2 cup butter",
"2 eggs",
"3/4 cup milk"
],
"recipeInstructions": [
{
"#type": "HowToStep",
"name": "Preheat",
"text": "Preheat the oven to 350 degrees F. Grease and flour a 9x9 inch pan.",
"url": "https://example.com/party-coffee-cake#step1",
"image": "https://example.com/photos/party-coffee-cake/step1.jpg"
},
{
"#type": "HowToStep",
"name": "Mix dry ingredients",
"text": "In a large bowl, combine flour, sugar, baking powder, and salt.",
"url": "https://example.com/party-coffee-cake#step2",
"image": "https://example.com/photos/party-coffee-cake/step2.jpg"
},
{
"#type": "HowToStep",
"name": "Add wet ingredients",
"text": "Mix in the butter, eggs, and milk.",
"url": "https://example.com/party-coffee-cake#step3",
"image": "https://example.com/photos/party-coffee-cake/step3.jpg"
},
{
"#type": "HowToStep",
"name": "Spread into pan",
"text": "Spread into the prepared pan.",
"url": "https://example.com/party-coffee-cake#step4",
"image": "https://example.com/photos/party-coffee-cake/step4.jpg"
},
{
"#type": "HowToStep",
"name": "Bake",
"text": "Bake for 30 to 35 minutes, or until firm.",
"url": "https://example.com/party-coffee-cake#step5",
"image": "https://example.com/photos/party-coffee-cake/step5.jpg"
},
{
"#type": "HowToStep",
"name": "Enjoy",
"text": "Allow to cool and enjoy.",
"url": "https://example.com/party-coffee-cake#step6",
"image": "https://example.com/photos/party-coffee-cake/step6.jpg"
}
],
"aggregateRating": {
"#type": "AggregateRating",
"ratingValue": "5",
"ratingCount": "18"
},
"video": {
"#type": "VideoObject",
"name": "How to make a Party Coffee Cake",
"description": "This is how you make a Party Coffee Cake.",
"thumbnailUrl": [
"https://example.com/photos/1x1/photo.jpg",
"https://example.com/photos/4x3/photo.jpg",
"https://example.com/photos/16x9/photo.jpg"
],
"contentUrl": "http://www.example.com/video123.mp4",
"embedUrl": "http://www.example.com/videoplayer?video=123",
"uploadDate": "2018-02-05T08:00:00+08:00",
"duration": "PT1M33S",
"interactionStatistic": {
"#type": "InteractionCounter",
"interactionType": { "#type": "WatchAction" },
"userInteractionCount": 2347
},
"expires": "2019-02-05T08:00:00+08:00"
}
}
</script>
I have tried the following:
<cfset source = "https://www.allrecipes.com/recipe/216319/homemade-sweet-italian-sausage-mild-or-hot/">
<cfhttp method="get" url="#source#" result="theresult" useragent="Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.7 (KHTML, like Gecko) Chrome/5.0.391.0 Safari/533.7">
<cfhttpparam type="header" name="Accept-Encoding" value="gzip,deflate,sdch" >
<cfhttpparam type="header" name="Proxy-Connection" value="keep-alive" >
<cfhttpparam type="header" name="Accept" value="application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5">
<cfhttpparam type="header" name="Accept-Language" value="en-US,en;q=0.8">
<cfhttpparam type="header" name="Accept-Charset" value="ISO-8859-1,utf-8;q=0.7,*;q=0.3">
<cfhttpparam type="cookie" name="some-cookie" value="1">
</cfhttp>
With he above I get the web page.
I then try to extract the JSON:
<cfscript>
// Create the jsoup object
Jsoup = createObject("java", "org.jsoup.Jsoup");
// HTML string
html = "#theresult.filecontent#";
// Parse the string
document = Jsoup.parse(html);
// Extract content
title = document.title();
tags = document.select("script[type=application/ld+json]");
</cfscript>
<cfdump var="#tags#">
<cfloop index="e" array="#tags#">
<cfoutput>
#e.attr("content")#<br>
</cfoutput>
</cfloop>
But I get nothing returned.
<script type="application/ld+json">[
{
"#context": "http://schema.org",
"#type": "BreadcrumbList",
...
}
</script>
The <script> tag doesn't have an attribute named "content" (only one named "type"). To retrieve the tag contents (or its inner html) use the Element.html() method. Then deserialize the returned contents as json:
<cfscript>
Jsoup = createObject("java", "org.jsoup.Jsoup");
document = Jsoup.parse( theResult.fileContent );
tag = document.select("script[type=application/ld+json]").first();
if (isJSON(tag.html())) {
contents = deserializeJSON( tag.html() );
writeDump(contents);
}
</cfscript>

Converting Google Cloud Vision OCR X and Y Co-ordinates to bbox Co-ordinates

Google Cloud Vision OCR has the following Output for a bounding box Object.
vertices {
x: 786
y: 967
}
Desired Output Format for Bounding Box
I want to go ahead and convert these co-ordinates to bounding box co-ordinates to write them in my hOCR format.
Which includes the following format for writing those in the file.
<span class='ocr_line' title="bbox 348 797 1482 838; baseline -0.009 -6">
Questions?
So how can I convert these x and y co-ordinates to these bbox (Bounding Box Co-ordinates).
What are these x and y co-ordinates is it (x_min, y_max) or (x_max, y_min). In general I want to also know what do these x and y represent?
Working on Image
I am working on the following image as my test.
As informed by #Christoph Rackwitz in the coments, this value is just a point. Each letter will be indicated by a set of 4 of this points, creating a bbox, like the following:
{
"description": "وأما",
"boundingPoly": {
"vertices": [
{
"x": 1088,
"y": 230
},
{
"x": 1145,
"y": 230
},
{
"x": 1145,
"y": 289
},
{
"x": 1088,
"y": 289
}
]
}
},
And the entire Page will be on the first object, as following:
{
"locale": "ar",
"description": "وأما ثانيا : فلأنه يخرج منه من زنی مثلا ثم جب ذكرة فإنه\nلا يتأتی\nمنه غير الندم على ما مضی ، وأما العزم على عدم\nقال : إن الندم\nيكفي في حد التوبة ، وليس كما قال ؛ لانه لو ندم ولم يقلع\nوعزم على العود لم يكن تائبا اتفاقا ، قال : وقال بعض المحق قين :\nاختيار ترك ذنب سبق حقيقة. أو تقديرا لأجل ال له قال :\nالعود فلا يتصور منه ، قال : وبهذا اغتر من\nهي\nوهذا أسد العبارات وأجمعها لأن التائب لا يكون تار کا\nل لذنب الذي فرغ لأنه غير متمكن من عينه لا تركا ولا فعلا ،\nمثله حقيقة ، وكذا من لم يقع منه ذنب\nمتمكن\nوإنما هو\nمن\nإنما يصح منه اتقاء ما يمكن أن يقع لا ترك مثل ما وقع فيكون\nمتقيا لا تائبا ، قال : والباعث على هذا تنبيه إلهي لمن أراد\nمهلك يفوث على\nلأنه\nسم\nسعادته لقبح الذنب وضر ره ؛\nالإنسان سعادة الدنيا والآخرة ويحجبة عن معرفة ال له. تعالي في\nالدنيا ، وعن تقريبه في الآخرة\nقال : ومن تفقد نفسه وجدها مشحونة بهذا السم فإذا وفق\nانبعث منه خوف هجوم الهلاك عليه ، فيبادر بطلب ما يدفع\n",
"boundingPoly": {
"vertices": [
{
"x": 122,
"y": 223
},
{
"x": 1197,
"y": 223
},
{
"x": 1197,
"y": 1688
},
{
"x": 122,
"y": 1688
}
]
}
},
You can process the json with the 4 points to generate the object you need.
Check this page, where you can Try the API. I have used the image url of the upload on stack overflow as the image source (i.e "imageUri": "https://i.stack.imgur.com/9MXec.jpg")

Import json array of objects to Elastic Search App

I have following sample json data with structure
[{
"URL": "http://www.just-eat.co.uk/restaurants-bluebreeze-le3/menu",
"_id": "55f14313c7447c3da7052518",
"address": "56 Bonney Road",
"address line 2": "Leicester",
"name": "Blue Breeze Fish Bar",
"outcode": "LE3",
"postcode": "9NG",
"rating": 5.5,
"type_of_food": "Fish \u0026 Chips"
},
{
"URL": "http://www.just-eat.co.uk/restaurants-bluebreeze-le3/menu",
"_id": "55f14313c7447c3da7052519",
"address": "56 Bonney Road",
"address line 2": "Leicester",
"name": "Blue Breeze Fish Bar",
"outcode": "LE3",
"postcode": "9NG",
"rating": 5.5,
"type_of_food": "Fish \u0026 Chips"
},
...... and so on thousands of objects
]
So i am trying to import this json data to Elastic Search App cluster i created... But i get error in all documents as follows
Indexing Summary
Something went wrong. Please address the errors and try again.
2548 documents with errors...
they didn't give any error details... just said listed all my objects with "semicolon highlighted"...
Can anyone tell me why am i not able to upload the data?

Accessing a nested JSON file in Flutter

I am trying to access the 'title' from the following list but it keeps throwing error.
var moviesDB = {
"genres": [
"Comedy",
"Fantasy",
"Crime",
"Drama",
"Music",
"Adventure",
"History",
"Thriller",
"Animation",
"Family",
"Mystery",
"Biography",
"Action",
"Film-Noir",
"Romance",
"Sci-Fi",
"War",
"Western",
"Horror",
"Musical",
"Sport"
],
"movies": [
{
"id": 1,
"title": "Beetlejuice",
"year": "1988",
"runtime": "92",
"genres": ["Comedy", "Fantasy"],
"director": "Tim Burton",
"actors": "Alec Baldwin, Geena Davis, Annie McEnroe, Maurice Page",
"plot":
"A couple of recently deceased ghosts contract the services of a \"bio-exorcist\" in order to remove the obnoxious new owners of their house.",
"posterUrl":
"https://images-na.ssl-images-amazon.com/images/M/MV5BMTUwODE3MDE0MV5BMl5BanBnXkFtZTgwNTk1MjI4MzE#._V1_SX300.jpg"
},
{
"id": 2,
"title": "The Cotton Club",
"year": "1984",
"runtime": "127",
"genres": ["Crime", "Drama", "Music"],
"director": "Francis Ford Coppola",
"actors": "Richard Gere, Gregory Hines, Diane Lane, Lonette McKee",
"plot":
"The Cotton Club was a famous night club in Harlem. The story follows the people that visited the club, those that ran it, and is peppered with the Jazz music that made it so famous.",
"posterUrl":
"https://images-na.ssl-images-amazon.com/images/M/MV5BMTU5ODAyNzA4OV5BMl5BanBnXkFtZTcwNzYwNTIzNA##._V1_SX300.jpg"
},
]
}
I can go as far as moviesDB["movies"][0] but cannot get the title property.
Although I can do the same in Javascript and it works with no errors.
console.log(moviesDB["movies"][0]["title"]);
Any solution for this?
You need to make a cast on the element of your movie list.
print((moviesDB['movies'][0] as Map<String, dynamic>)['title']);

Nested ng-repeat is not working while parsing json data from a wordpress website

I am developing a news app using Ionic. News is coming from a wordpress site in json format. Here is a small chunk of the json.
{
"status": "ok",
"count": 100,
"count_total": 4104,
"pages": 42,
"posts": [
{
"id": 57063,
"type": "post",
"slug": "%e0%a6%b6%e0%a6%bf%e0%a6%ac%e0%a6%bf%e0%a6%b0%e0%a7%87%e0%a6%b0-%e0%a6%95%e0%a7%87%e0%a6%a8%e0%a7%8d%e0%a6%a6%e0%a7%8d%e0%a6%b0%e0%a7%80%e0%a7%9f-%e0%a6%a8%e0%a7%87%e0%a6%a4%e0%a6%be-%e0%a6%8f",
"url": "http://latestkhobor.com/%e0%a6%b8%e0%a6%be%e0%a6%b0%e0%a6%be%e0%a6%a6%e0%a7%87%e0%a6%b6/%e0%a6%9a%e0%a6%9f%e0%a7%8d%e0%a6%9f%e0%a6%97%e0%a7%8d%e0%a6%b0%e0%a6%be%e0%a6%ae-%e0%a6%ac%e0%a6%bf%e0%a6%ad%e0%a6%be%e0%a6%97/%e0%a6%b6%e0%a6%bf%e0%a6%ac%e0%a6%bf%e0%a6%b0%e0%a7%87%e0%a6%b0-%e0%a6%95%e0%a7%87%e0%a6%a8%e0%a7%8d%e0%a6%a6%e0%a7%8d%e0%a6%b0%e0%a7%80%e0%a7%9f-%e0%a6%a8%e0%a7%87%e0%a6%a4%e0%a6%be-%e0%a6%8f/",
"status": "publish",
"title": "শিবিরের কেন্দ্রীয় নেতা এনামুল চট্টগ্রামে গ্রেফতার",
"title_plain": "শিবিরের কেন্দ্রীয় নেতা এনামুল চট্টগ্রামে গ্রেফতার",
"content": "<p style=\"text-align: justify;\"><img class=\"alignleft size-thumbnail wp-image-57037\" src=\"http://latestkhobor.com/wp-content/uploads/2015/02/enamul_224231-150x150.jpg\" alt=\"enamul_224231.jpg\" width=\"150\" height=\"150\" />নাশকতার অভিযোগে ছাত্রশিবিরের কেন্দ্রীয় কার্যকরী পরিষদের সদস্য এনামুল কবিরকে গ্রেফতার করেছে চট্টগ্রাম মহানগর পুলিশ। শুক্রবার তাকে নগরীর বাকলিয়া থানার বগার বিল এলাকা থেকে গ্রেফতার করে পুলিশ।</p>\n<p style=\"text-align: justify;\">নগর পুলিশের অতিরিক্ত কমিশনার (অপরাধ ও অভিযান) বনজ কুমার মজুমদার গ্রেপ্তারের বিষয়টি নিশ্চিত করেছেন।</p>\n<p style=\"text-align: justify;\">পুলিশ সূত্রে জানা গেছে এ বিষয়ে আরো জানানো হয়, এনামুলের সঙ্গে চট্টগ্রামেরও কয়েকজন শিবিরের নেতাকর্মীকে আটক করা হয়েছে।</p>\n",
"excerpt": "<p>নাশকতার অভিযোগে ছাত্রশিবিরের কেন্দ্রীয় কার্যকরী পরিষদের সদস্য এনামুল কবিরকে গ্রেফতার করেছে চট্টগ্রাম মহানগর পুলিশ। শুক্রবার তাকে নগরীর বাকলিয়া থানার বগার বিল এলাকা থেকে গ্রেফতার করে পুলিশ। নগর পুলিশের অতিরিক্ত কমিশনার (অপরাধ ও অভিযান) বনজ কুমার মজুমদার গ্রেপ্তারের বিষয়টি নিশ্চিত করেছেন। পুলিশ সূত্রে জানা গেছে এ বিষয়ে আরো জানানো হয়, এনামুলের সঙ্গে চট্টগ্রামেরও কয়েকজন শিবিরের নেতাকর্মীকে …</p>\n",
"date": "2015-02-21 15:38:41",
"modified": "2015-02-21 15:38:41",
"categories": [
{
"id": 960,
"slug": "%e0%a6%9a%e0%a6%9f%e0%a7%8d%e0%a6%9f%e0%a6%97%e0%a7%8d%e0%a6%b0%e0%a6%be%e0%a6%ae-%e0%a6%ac%e0%a6%bf%e0%a6%ad%e0%a6%be%e0%a6%97",
"title": "চট্টগ্রাম বিভাগ",
"description": "",
"parent": 11,
"post_count": 50
},
{
"id": 48,
"slug": "%e0%a6%ac%e0%a7%8d%e0%a6%b0%e0%a7%87%e0%a6%95%e0%a6%bf%e0%a6%82-%e0%a6%a8%e0%a6%bf%e0%a6%89%e0%a6%9c",
"title": "breaking",
"description": "",
"parent": 0,
"post_count": 1132
},
{
"id": 11,
"slug": "%e0%a6%b8%e0%a6%be%e0%a6%b0%e0%a6%be%e0%a6%a6%e0%a7%87%e0%a6%b6",
"title": "সারাদেশ",
"description": "",
"parent": 0,
"post_count": 1347
}
],
I want to show a particular news sorting by category. Like I want to show news what is into "breaking" category. I tried this code but it's not happening right.
<ion-item class="item-thumbnail-left" ng-repeat="singleNews in news.posts" href="#/app/singleNews/{{singleNews.id}}">
<span ng-repeat="cat in singleNews.categories | filter: {title: 'breaking'}">
<img src="{{singleNews.thumbnail}}">
<h2 ng-bind-html="singleNews.title"></h2>
<div ng-bind-html="singleNews.excerpt"></div>
</span>
</ion-item>
I believe for better solution you need to create a custom filter. that will filter out if title is matching {title: 'special'}
app.filter('filterForTitle',function($filter){
return function(news, prop1){
var returnValue = [];
angular.forEach(news,function(values,index){
var matchedValue = $filter('filter')(values.categories,{title:'special'},true);
if(matchedValue.length>0) returnValue.push(values);
});
return returnValue;
}
});
HTML
<ion-item class="item-thumbnail-left" href="#/app/singleNews/{{singleNews.id}}" ng-repeat="singleNews in news.posts|filterForTitle">
<img src="{{singleNews.thumbnail}}">
<h2 ng-bind-html="singleNews.title"></h2>
<div ng-bind-html="singleNews.excerpt"></div>
</ion-item>
Working CodePen
Filtered array is returning duplicate values everytime, i think service is only returning duplicate values.
For solving that issue we need to filter for inner ng-repeat like filter:{title: 'special'}" Thats weird part .
I did a little trick and it worked. I just wrote the first ng-repeat outside of the ion-item tag. Here is the working code of the ion-list
<div ng-repeat="singleNews in news.posts">
<ion-item class="item-thumbnail-left" ng-repeat="cat in singleNews.categories | filter: {title: 'ক্রিকেট'}" href="#/app/singleNews/{{singleNews.id}}">
<img src="{{singleNews.thumbnail}}">
<h2 ng-bind-html="singleNews.title"></h2>
<div ng-bind-html="singleNews.excerpt"></div>
</ion-item>
</div>