Extract JSON from Facebook Marketing API using XPATH in Talend - json

currently I am extracting data from the Facebook Marketing API.
I am Using an XPATH query in Talend Studio for the JSON i get via the API.
Since this is my first Job with JSON and XPATH I need some help with the following extraction:
At first a part of my JSON:
{
"data": [
{
.
.
.
"adsets": {
"data": [
{
.
.
.
"targeting": {
"age_max": 60,
"age_min": 18,
"geo_locations": {
"countries": [
"DE"
]
},
"facebook_positions": [
"feed",
"right_hand_column"
],
.
.
.
Now i want to extract from "facebook_positions" with XPATH:
"/data/adsets/data/targeting/facebook_positions"
with that XPATH query I only get "feed" as my result but I need "feed,right_hand_column" since there are no keys to the values like ' "age_max": 60' I am not able to extract the correct path.
Thanks in advance for your help!
Best Regards
CoGe

Have you tried :-
//facebook_positions
OR
//facebook_positions[1] -> feed
//facebook_positions[2] -> right_hand_column
Example :-
Open below URL:
http://www.jsonquerytool.com/
{
"data": [{
"adsets": {
"data": [{
"targeting": {
"age_max": 60,
"age_min": 18,
"geo_locations": {
"countries": [
"DE"
]
},
"facebook_positions": [
"feed",
"right_hand_column"
]
}
}]
}
}]
}
Select Query for JSON as :-
Xpath for JSon
put the query as :-
//facebook_positions
Click on Run

Related

LUIS Import Dataset: BadArgument: Dataset object cannot be null. Parameter name: dataSet

Good day community, I am using LUIS to train a data set to let it classified between different meaning of the words. After I've done trained, I want to import a set of data to let it test. There is a batch testing options for me to import a json file, however it keeps showing this error:
BadArgument: Dataset object cannot be null. Parameter name: dataSet
I have already follow the json format that it gave which is like this:
[
{
"text": "hey dad, are you hungry?",
"intent": "None",
"entities":
[
{
"entity": "FamilyMember",
"startPos": 4,
"endPos": 6
}
]
},
{
.
.
.
}
]
My json file has the format like this:
[
{
"text" : "Hello"
"intent": "Greetings"
},
{
"text" : "I want bread"
"intent": "Request"
}
]
Can anyone tell me what am I doing wrong? The training doesn't include any entities so I did not put it into my json file.
Thank you.
You still need to provide the entities attribute and give it an empty array, otherwise you'll receive a different error. Regarding your format, you're missing commas after your text attributes.
[
{
"text" : "Hello",
"intent": "Greetings",
"entities": []
},
{
"text" : "I want bread",
"intent": "Request",
"entities": []
}
]
When I used the above code the batch test successfully completed for me.

I want to populate my WordPress website with a json file. How can that be done?

This is the json format:
{
"Album": [
{
"name": "despacito",
"lang": "spanish",
"thumbnail": "some-url",
"scrn":"some-url",
"ourl":"some-url",
"YearOfRelease": 2017
}
]
}
How can this JSON be displayed on a WordPress site. Please do share if there is any tutorial on this or try to help me doing this.
Using PHP
Decode the json object using json_decode($obj)
refer : Decoding json in php
{
"Album": [
{
"name": "despacito",
"lang": "spanish",
"thumbnail": "some-url",
"scrn":"some-url",
"ourl":"some-url",
"YearOfRelease": 2017
}
]
}
to retrieve name, use
$obj->Album->name
OR
foreach($obj-> Album as $value){
echo $value->name; //change accordingly
}
Sources : json_decode to array

Talend XPath syntax problems when trying to access Google Translate API Response

I am trying to parse multiple translations in Talend using a tExtractJSONFields component. I am not that familiar with XPath.
{
"data": {
"translations": [
{
"translatedText": "Bonjour"
},
{
"translatedText": "Au Revoir"
}
]
}
}
When I am only translating a single element, this configuration works:
However when I am requesting multiple translations, I am trying to guess at the syntax to pull out the different translatedText values in the response.
For example, this doesn't work it seems:
Any help appreciated. I am sending 4 items for translation so expect an array of 4 JSON objects each with a "translatedText" property.
Updated:
Response with 4 items is as below:
{
"data": {
"translations": [
{
"translatedText": "Product 1"
},
{
"translatedText": "04/12/1984"
},
{
"translatedText": "Withdrawn"
},
{
"translatedText": "national"
}
]
}
}
When I try this:
I get close, but all the output looks like it has square brackets around it indicating an array of sorts.
And I have tried the above with "translations[0]/translatedText[0]" as the XPath query and it does the same thing.
Actually this seems to have worked:

elasticsearch search for elements with specified ID example

I want to find certain elements in my elastic search that have a given ID and I can't figure an easy way to do this.
I see http://www.elasticsearch.org/guide/reference/query-dsl/ids-query/ but can't for the life of me figure out how to structure a query to use it, or when I do toy around with es-head or curl I see errors like:
Parse Failure [Failed to parse source [{"query":{"match_all":{}},"ids
{"values""1","4","100"]}}]]]; nested: SearchParseException[[dailyaggregates][4]:
query[ConstantScore(NotDeleted(*:*))],from[-1],size[-1]: Parse Failure [No parser for
element [ids]]]; }]
etc. Can anyone tell me how to set this up? Thanks.
edit: My attempt with that error was from es-head but similar errors through curl. I believe what I tried was some variant of this:
{
"query": {
"match_all": {}
},
"ids": {
"values": [
"100"
]
}
}
ids is a type of query, just like match, or match_all. So the format should be:
{"query":{ "ids":{ "values": [ 100 ] } } }
You can alternatively do it as a filter, like so:
{"filter":{ "query": {"ids":{ "values": [ 100 ] } } } }

trying to get MySQL data into nested json file for d3?

I am trying to get MySQL database data into json format. My file needs to be in the format of nested parents and children. (see snippet) This is because I am trying to use a d3 data visualization (collapsible tree layout) that requires that the json data be formatted in a certain way. Below I have attached a snippet of what I the json file to look like. I am having some issues trying to write nested sql statements to do this. I have also attached a visual of my database to see what I am dealing with. Any advice will help greatly. Thanks!
The json format I am trying to get is something like this:
{
"name": "Projects",
"children": [
{
"name":"category_name#1", "description":"category",
"children": [
{
"name":"sub_category_name1",
"description":"category description text here",
"children":[
{"name": "project1",
"description":"project 1 text goes here",
"children":[
{"name":"mike", "email":"xxx#mail.com"},
{"name":"dan", "email":"xxx#gmail.com"}
]
},
{
"name": "project2",
"description":"project 2 text goes here",
"children":[
{"name":"steve", "email":"xxx#mail.com"},
{"name":"chris", "email":"xxx#gmail.com"}
]
}
]
},
{
"name": "sub_category_name2",
"description":"sub category description text goes here..",
"children": [
{"name": "project3",
"description":"project3 text goes here ",
"children":[
{"name":"Alex", "email":"xxx#gmail.com"}
]
}
]
}
]
},
.
. //more categories with children of subcategories and sub_cat children of projects
.
}
I've had success with this tutorial in the past:
http://www.d3noob.org/2013/02/using-mysql-database-as-source-of-data.html
In short what you'll do is create a php file that connects to MySql, performs a query and translates the results into json. You'll then use this file in place of the data source in your d3 code.