I want this multilevel array of jason in angular format i am not being able to do it.
Json file to be displayed in angular goes here.
I am able to display properties and geometry not others
{
"type": "FeatureCollection", //first fie
"metadata": {
"generated": 1456209730000,
"api": "1.4.0",
},
"features": [
{
"type": "Feature",
"properties": {
"mag": 2.3,
},
"geometry": {
"type": "Point",
"coordinates": [
-150.7703,
63.5849
]},
"id": "ak12869032"
},
{
"type": "Feature",
"properties": {
"mag": 2.43
},
"geometry": {
"type": "Point",
"coordinates": [
-120.8253326,
36.6078339
]},
"id": "nc72596150"
}],
"bbox": [ //last field
-150.7703,
33.7698333
]}
Please follow these steps:
1) create $scope.tempData variable in your controller
2) get your value in $scope
3) $scope.tempData=[your json data];
4) you can use tempData in anywhere within controller.
for(var d in tempData)
{
var data=tempData[d].id;
}
now you are able to getting id from your json.but for its giving last value.
so you can cretae array and pushed on every loop.
5) if you want use in html can use ng-repeat.
If you are beginner vist my blog.
Edit your json:
{
"type": "FeatureCollection",
"metadata": {
"generated": 1456209730000,
"api": "1.4.0",
"count": 3
},
"features": [
{
"type": "Feature",
"properties": {
"mag": 2.3,
"place": "93km WNW of Cantwell, Alaska",
"time": 1456207082000
},
"geometry": {
"type": "Point",
"coordinates": [
-150.7703,
63.5849
]
},
"id": "ak12869032"
},
{
"type": "Feature",
"properties": {
"mag": 2.43,
"place": "42km WSW of Mendota, California",
"time": 1456206494170
},
"geometry": {
"type": "Point",
"coordinates": [
-120.8253326,
36.6078339
]
},
"id": "nc72596150"
}
],
"bbox": [
-150.7703,
33.7698333,
0.79,
-115.9471667,
63.5849,
8.8
]
}
See the points: http://bl.ocks.org/d/60bc280edef4ed4da464
To display json in angularjs, please use filter json with model.
<input type="text" ng-model="(jsonData | json)">{{jsonData | json}}</input>
Using Pre Tag we can style it in html page
In your Controller:
$scope.details={name:"xyz",address:[{place:"cc"},{place:"second"}]}
In HTML Page: <pre>{{details|json}}</pre>
Related
I've been trying to build an index in ES and add the initial items to it (around 350k), using PHP.
I tried all kinds of batch sizes (from 10 items to 1k), check the count, check the threshold, but for some reason it doesn't index every item.
It just skips over some random items, without any errors in the batch result response. I feel like I tried everything and I have to idea what to do next
I'm using Amazon OpenSearch with the latest supported ES (7.10).
The index looks like this:
{
"wonder-search": {
"aliases": {},
"mappings": {
"properties": {
"address": {
"type": "text"
},
"city": {
"type": "text"
},
"city_id": {
"type": "integer"
},
"duration": {
"type": "integer"
},
"filename": {
"type": "text"
},
"geo_point": {
"type": "geo_point"
},
"icon": {
"type": "keyword"
},
"is_sandbox": {
"type": "integer"
},
"item_id": {
"type": "integer"
},
"item_label": {
"type": "keyword"
},
"latitude": {
"type": "float"
},
"longitude": {
"type": "float"
},
"search_text_caption_json": {
"type": "text",
"index_phrases": true
},
"search_text_city_json": {
"type": "text",
"index_phrases": true
},
"search_text_completion": {
"type": "completion",
"analyzer": "simple",
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50,
"contexts": [
{
"name": "type",
"type": "CATEGORY"
}
]
},
"search_text_country_json": {
"type": "text",
"index_phrases": true
},
"search_text_cuisine_name_json": {
"type": "text",
"index_phrases": true
},
"search_text_location_name_json": {
"type": "text",
"index_phrases": true
},
"search_text_state_json": {
"type": "text",
"index_phrases": true
},
"search_text_tag_name_json": {
"type": "text",
"index_phrases": true
},
"search_text_username_json": {
"type": "text",
"index_phrases": true
},
"sort": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"sort_score": {
"type": "double"
},
"type": {
"type": "text"
},
"user_icon": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"user_id": {
"type": "integer"
},
"username": {
"type": "keyword"
},
"vanity_url": {
"type": "keyword"
},
"video_count": {
"type": "integer"
}
}
},
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"mapping": {
"ignore_malformed": "true"
},
"number_of_shards": "1",
"provided_name": "wonder-search",
"creation_date": "1671003076106",
"number_of_replicas": "1",
"uuid": "YQh1q40WTneLE4MWDWhArw",
"version": {
"created": "7100199"
}
}
}
}
}
and one item looks like this:
{
"_index": "wonder-search",
"_type": "_doc",
"_id": "wq2LD4UBUAuy7FQPhtZh",
"_version": 1,
"_seq_no": 2003,
"_primary_term": 1,
"found": true,
"_source": {
"sort": "4004",
"item_id": "4934",
"user_id": "434",
"user_icon": "/site-content/avatars/Sp8AXjTJvMbRao2oZbuiUuSVH042-1597776099045.jpeg",
"username": "chuurros",
"item_label": "Kyoto Katsugyu【京都勝牛】",
"search_text_username_json": [
"chuurros"
],
"search_text_caption_json": [
"Absolutely love their gyukatsu (beef katsu) here! Delicious and will keep you wanting more! 🥰"
],
"search_text_city_json": [
"Toronto"
],
"search_text_state_json": [
"Ontario"
],
"search_text_country_json": [
"Canada"
],
"search_text_location_name_json": [
"Kyoto Katsugyu【京都勝牛】"
],
"search_text_tag_name_json": [
"japanese",
"restaurant",
"asian",
"dining",
"topcollection-4934"
],
"search_text_cuisine_name_json": [],
"type": "video",
"vanity_url": "",
"icon": "",
"city": "Toronto",
"city_id": "439",
"latitude": "43.65682410",
"longitude": "-79.37617410",
"address": "134 Dundas St E",
"duration": "9.57",
"video_count": "0",
"sort_score": "43",
"filename": "373d75fd-4292-4e5b-a239-4b1c39ffc86c.MOV",
"is_sandbox": "0",
"geo_point": {
"lat": "43.65682410",
"lon": "-79.37617410"
},
"search_text_completion": {
"input": [
"Kyoto Katsugyu【京都勝牛】"
],
"contexts": {
"type": [
"video"
]
}
}
}
}
Any ideas why does it work like this?
There is json response:
{
"id": "1234567890123456789",
"creation_date": 12345678,
"event": "WAITING_PAYMENT",
"version": "2.0.0",
"data": {
"product": {
"id": 213344,
"name": "Product Name",
"has_co_production": false
},
"affiliates": [
{
"name": "Affiliate name"
}
],
"buyer": {
"email": "buyer#email.com"
},
"producer": {
"name": "Producer Name"
},
"commissions": [
{
"value": 0.65,
"source": "MARKETPLACE"
},
{
"value": 3.10,
"source": "PRODUCER"
}
],
"purchase": {
"approved_date": 1231241434453,
"full_price": {
"value": 134.0
},
"original_offer_price": {
"currency_value": "EUR"
"value": 100.78,
},
"price": {
"value": 150.6
},
"order_date": "123243546",
"status": "STARTED",
"transaction": "HP02316330308193",
"payment": {
"billet_barcode": "03399.33335 33823.303087 198801027 2 876300015000",
"billet_url": "https://billet-link.com/bHP023163303193",
}
},
"subscription": {
"status": "ACTIVE",
"plan": {
"name": "plan name"
},
"subscriber": {
"code": "12133421"
}
}
}
}
My question is how to extract data["buyer"]["email"] in PHP ?
I only need to extract the email information from the buyer table inside the data table.
First, you need to decode the json to a PHP array (or an object), then you can access the requested information from the decoded data.
$data = json_decode('the json string most place here', true);
$email = $data['buyer']['email'];
Place your json string in the first argument of json_decode() function.
I've some trouble with parsing a JSON file into a MySQL database. It's an export of some Facebookstats.
Because I've multiple export of multiple pages, it's important that I've the corresponding ID in the database.
The JSONfile (or cURL from Facebook) looks like this:
{
"data": [
{
"name": "impressions",
"period": "week",
"values": [
{
"value": 123456789,
"end_time": "2016-01-01T08:00:00+0000"
},
{
"value": 12345678,
"end_time": "2016-01-02T08:00:00+0000"
},
{
"value": 1234567,
"end_time": "2016-01-03T08:00:00+0000"
},
{
"value": 123456,
"end_time": "2016-01-04T08:00:00+0000"
},
{
"value": 12345,
"end_time": "2016-01-05T08:00:00+0000"
}
],
"title": "Weekly Impressions",
"description": "The number of impressions seen of any content associated with your Page. (Total Count)",
"id": "101010101010\/insights\/page_impressions\/week"
}
],
"paging": {
"previous": "1",
"next": "2"
}
}
I would, ideally, parse this data into a MySQL database that looks like this:
id value end_time
101010101010 123456789 2016-01-01T08:00:00+0000
101010101010 12345678 2016-01-02T08:00:00+0000
101010101010 1234567 2016-01-03T08:00:00+0000
101010101010 123456 2016-01-04T08:00:00+0000
101010101010 12345 2016-01-05T08:00:00+0000
I hope someone had some ideas :-)
Use json_decode(). Example:
$jsonString = '{
"data": [
{
"name": "impressions",
"period": "week",
"values": [
{
"value": 123456789,
"end_time": "2016-01-01T08:00:00+0000"
},
{
"value": 12345678,
"end_time": "2016-01-02T08:00:00+0000"
},
{
"value": 1234567,
"end_time": "2016-01-03T08:00:00+0000"
},
{
"value": 123456,
"end_time": "2016-01-04T08:00:00+0000"
},
{
"value": 12345,
"end_time": "2016-01-05T08:00:00+0000"
}
],
"title": "Weekly Impressions",
"description": "The number of impressions seen of any content associated with your Page. (Total Count)",
"id": "101010101010\/insights\/page_impressions\/week"
}
],
"paging": {
"previous": "1",
"next": "2"
}
}';
Then decode it to an associative array:
$assocData = json_decode($jsonString, true); //Setting second optional parameter to true makes it return an associative array.
Then access it however you want:
$data = $assocData['data'];
I'm trying to validate a json object using the "justinrainbow/json-schema" package for php.
Here's the json that i'm trying to validate:
{
"questions": [
{
"type": "section",
"name": "Section one",
"questions": [
{
"type": "section",
"name": "Subsection 1.1"
"questions":[
{
"type": "section",
"name": "Subsection 1.1"
"questions":
[
{
...
}
]
}
]
}
]
}
]
The questions property can always be present inside questions property ....
How can i validate it?
Thank you for your answers
You can use $ref to define a recursive structure.
{
"type": "object",
"properties": {
"type": { "type": "string" },
"name": { "type": "string" },
"questions": { "type": "array", "items": { "$ref": "#"} }
}
}
Fetching data from mySQL and Generating json through php like this:
while ($row = mysql_fetch_array($result)) {
$menu[] = array("type"=>"FeatureCollection",
"features" => [array("type"=>"Feature",
"geometry"=>array("type"=>"Point",
"coordinates"=>[-77.034084142948,38.909671288923]),
"properties"=>array("phone"=>"041","city"=>"Faisalabad","country"=>"Pakistan"))]
);
} $json = json_encode($menu);
echo $json;
and the result looks like this:
[
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-77.034084142948,
38.909671288923
]
},
"properties": {
"phone": "041",
"city": "Faisalabad",
"country": "Pakistan"
}
}
]
},
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-77.034084142948,
38.909671288923
]
},
"properties": {
"phone": "041",
"city": "Faisalabad",
"country": "Pakistan"
}
}
]
},
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-77.034084142948,
38.909671288923
]
},
"properties": {
"phone": "041",
"city": "Faisalabad",
"country": "Pakistan"
}
}
]
}]
As you can see {"type": "FeatureCollection","features":[{...}]}is being repeated three time, I want it to appear at the beginning only like following json, so that {"type": "FeatureCollection","features":[{I WANT LOOP HERE only}]}: I want this result:
[
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-77.034084142948,
38.909671288923
]
},
"properties": {
"phone": "041",
"city": "Faisalabad",
"country": "Pakistan"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-77.034084142948,
38.909671288923
]
},
"properties": {
"phone": "041",
"city": "Faisalabad",
"country": "Pakistan"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-77.034084142948,
38.909671288923
]
},
"properties": {
"phone": "041",
"city": "Faisalabad",
"country": "Pakistan"
}
}
]
}]
Please help I have been trying too much. Thanks
Well, why do you keep repeating "FeatureCollection" in the while-loop if you only want it once?
I think you want something like this:
$menu = array();
features = array();
$menu['type'] = 'FeatureCollection';
while ($row = mysql_fetch_array($result)) {
$features[] = array("type"=>"Feature",
//Other features here
);
}
$menu['features'] = $features;
In your $menu array you shoud define key type with value FeatureCollection, and key features. And in your while loop do this:
$menu = array(
'type' => 'FeatureCollection',
'features' => array()
);
while ($row = mysql_fetch_array($result)) {
$menu[`features`][] = array(...);
}