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:
Related
I'm trying to write a JsonPath query that selects a specific object based on a condition, but either the syntax fails me or I fail the syntax.
Given the below Json object, how would I select the "Data" object containing Dirk Gently's details based on the fact that he uses the "Stumble" method?
{
"Investigators": [
{
"Type": "Legend",
"Object": {
"Method": "Investigate",
"Data": {
"Name": "Sherlock",
"Surname": "Holmes"
}
}
},
{
"Type": "Visionary",
"Object": {
"Method": "Stumble",
"Data": {
"Name": "Dirk",
"Surname": "Gently"
}
}
}
],
"Version": 1
}
I know that I can get to the Method-field like this:
$.Investigators..Object.Method
I assumed that something like this would work:
$.Investigators..Object[?(#.Method=="Stumble")].Data
I'm testing this using: https://jsonpath.com/ to evaluate the query - and I can't seem to get it right.
Am I trying to do something that is not achievable or am I just making a stupid mistake?
Go to this jsonpath online sandbox and try this experssion:
$.Investigators..Object[?(#.Method=="Stumble")].Data
using either the Jayway or Gatling implementations, the output will be:
[
{
"Name" : "Dirk",
"Surname" : "Gently"
}
]
Trying to create a website that takes in information from an API, however I don't really understand how to do it seeing that I need all results grouped up and the API I've created almost never gives a response with the same amounts of objects. So the question is, seeing that I use vue.js and axios is there any way to loop through the json objects to show each of the objects in a seperate ? I manage to do it when there are a specified amounts, but I want to make it dynamic so I don't hardcode into the variables what part of the response I need to set to each variable.
UPDATE: I've tried to use v-for, but seeing that I need to have the output quite structured it doesn't really help, I've also tried Nested V-for loops, once again I can't get the accuracy that I'm looking for.
UPDATE2: Also should be added, when I say JSON object I actually ment js object. the json.parse() has been used on the json.
UPDATE3: Updated the JSON to actual data that I'm using for the application.
Every div need a lemma, a paradigm tagset, inflection tagset and inflectionForms and a table for all the meanings. Just need meaning not meaningText. TranslationId is not important. The JTranslate that wraps every object will be removed, just kinda tired of the Java at the moment, will do that later today and do the adjustments on the vue projects aswell regarding that deletion.
Actually your json format is invalid
{
"object1":{
"name": "test",
"data": "test"
},
"object2":{
"name": "test2",
"data": "test2"
},
"object3":{
"name": "test2",
"data": "test2"
}
}
it should be like above and use JSON.parse() method to simply convert the json to javascript object
Valid Object:
var objects = {
"object1":{
"name": "test",
"data": "test"
},
"object2":{
"name": "test2",
"data": "test2"
},
"object3":{
"name": "test2",
"data": "test2"
}
}
for iteration use
<div v-for="(object,index) in objects" :key="index">
{{object}}
</div>
The correct object as an array:
test: [
{
object1: {
name: 'name1',
data: 'content1'
}
},
{
object2: {
name: 'name1',
data: 'content1'
}
},
{
object3: {
name: 'name3',
data: 'content3'
}
}
]
can be mapped as a computed property inside the script tages:
computed: {
mappedTest() {
return this.test.map(entry => {
const key = Object.keys(entry)[0];
return { name: entry[key].name, data: entry[key].data };
});
}
},
and call it inside the template
<div
v-for="testObject in mappedTest"
:key="testObject"
>
name: {{testObject.name}}; data: {{testObject.data}}
</div>
I was very tired when I asked this question, apparently I did everything wrong. Can easily be solved by nested v-for loops.
I'm sending push notifications from a rails app through the parse.com REST API.
Targeting a single user works great but targeting more users with $in doesn't seem to work in my scenario.
Here's my JSON Code:
{
"where":
{
"user":
{
"__type":"Pointer",
"className":"_User",
"objectId":
{
"$in":["AAA","BBB","CCC"]
}
}
},
"data":
{ ...
Isn't it possible to use $in when targeting multiple users? I noticed that I'm also not able to to so in the parse.com push backend.
The response is:
{
"code": 106,
"error": "key objectId should be a string"
}
Anyone got an idea? I don't want to make an separate REST Call for every notification.
Okay, sorry I found the answer here: REST in Parse $in to ObjectID of Pointer Error Code 106
Or in short, this code works:
{
"where":
{
"user":
{
"$inQuery":
{
"where": {
"objectId":
{
"$in":["AAA","BBB","CCC"]
}
},
"className":"_User"
}
}
},
"data":
I want to 'get' just the first tier information from my firebase JSON via the REST api, without any of the nested arrays each object has. How can I do that with firebase, to avoid having to download the entire dataset?
i.e. from the JSON below I just want to return:
{ "people":[
{"name":"bob"},
{"name":"dave"}
]}
Full data
{
"people":[
{
"name":"bob",
"measurements":[
{
"measname":"first test",
"weights":[
{
"device":"scaleA",
"weight":78.0
},
{
"device":"scaleA",
"weight":78.2
}
]
}
]
},
{
"name":"bob",
"measurements":[
{
"measname":"first test",
"weights":[
{
"device":"scaleA",
"weight":78.0
},
{
"device":"scaleA",
"weight":78.2
}
]
}
]
}
]
}
Edit: I didn't realize you specified this needed to be server-side. According to this question, it doesn't seem to be possible: Database-style Queries with Firebase
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 ] } } } }