What is the json body in post request in order to fetch all rows from an operation list with key? - json

I have defined a list for operational data in yang model as:
list listener-state {
key “listener-name”;
config false;
description
“common statistics for given listener (i.e sent messages)”;
uses listener-state-info;
…
}
I use opendaylight api (org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream) which will convert the json body in request to org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode, in order to finally generate the XML rpc for confd server.
In my case, I want to fetch all rows from this operation list, then I try to make the json as :
“command”: {“service” : {“server” : {“listener-state” : {}}}},
I will get exception that : “Input is missing some of the keys of listener-state”
Then I can add the key value to the json body :
“command”: {“service” : {“server” : {“listener-state” : {“listener-name”: “first”}}}},
This case, I can only get one row. I also try to leave the key value as blank:
“command”: {“service” : {“server” : {“listener-state” : {“listener-name”: “”}}}},
Then the response will be all key values instead of all rows. So now my question is what the json will be in order to get all rows in the list without knowing the key values ?
This should be feasible since I figure out XML request can do that. But I can't figure out what the matching json will be.
Thanks.

I did bunch of investigation. Unfortunately, I don't think there is a way to fetch the whole table

Related

How can I get the id from a JSON object

How can I get the id of an object?
In this example I want to get the 'ok' and store it in a variable.
I know how to access the data.I need to access the id and store it for some purpose.
I use Angular so the console log is like this
'console.log (this.Data');'
{ok: Array(2)}
ok: Array(2)
.
.
.
Always depends in your JSON structure but if you want the object inside the 'ok' key you can access through the key, for example:
{
"ok": Array(2)
}
You can access with the key associated at the object:
this.Data.ok;
this.Data[ok];
Ok i find the solution.I changed the object.I set an 'id' and a 'data' field.Now i can access it like this.Data.id and this.Data.data.
You can get every key from your JSON with Object.keys.
Object.keys(this.data)

OpenEdge ABL reserved keyword as temp-table field name (inferred from JSON data)

I am stuck with the following situation:
My method receives a response from external REST API call. The JSON response structure is as below:
{
"members": [
{
"email_address": "random#address.org",
"status": "randomstatus"
},
...etc...
]}
I am reading this to temp-table with READ-JSON (Inferring ABL schema from JSON data) and try to process the temp-table. And this is where I am stuck:
when I am trying to put together a query that contains temp-table field "status", the error is raised.
Example:
hQuery:QUERY-PREPARE('FOR EACH ' + httSubscriber:NAME + ' WHERE ' + hBuffer:BUFFER-FIELD(iStatus):NAME + ' = "randomstatus"').
gives:
**Unable to understand after -- "members WHERE".(247)
I have tried referencing directly by name as well, same result.
Probably the "status" is a reserved keyword in ABL. Might that be the case? And how can I get over this issue to reference that "status" field?
Unfortunately the format and key names of JSON response are not under my control and I have to work with that.
You could use SERIALIZE-NAME in the temp-table definition to internally rename the field in question. Then you would have to refer to the field with another name but in it's serialized form it would still be known as status.
Here's an example where the status-field is renamed to exampleStatus.
DEFINE TEMP-TABLE ttExample NO-UNDO
FIELD exampleStatus AS CHARACTER SERIALIZE-NAME "status".
/* Code to read json goes here... */
/* Access the field */
FOR EACH ttExample:
DISPLAY ttExample.exampleStatus.
END.
I've been known to do silly things like this:
JSONData = replace( JSONData, '"status":', '"xstatus":' ).
Try naming the temp-table (hard-coded or via string appending) + '.' + hBuffer:BUFFER-FIELD(iStatus):NAME (...)
It should help the compiler understand you're talking about the field. Since it's not restricted, this should force its hand and allow you to query.

REST POST json body to support complex query advice

I'm fairly new to REST. All of our legacy webservices were SOAP based with enterprise (ORACLE or DB2) databases. We are now moving to REST/couchbase.
Our team is looking into implementing a complex query method. We already have implemented simple query methods using GET, for example GET returns all entries and a GET/067e6162-3b6f-4ae2-a171-2470b63dff00 would return the entry for 067e6162-3b6f-4ae2-a171-2470b63dff00.
We want to support a query method that would support receiving several query parameters such a list of Ids and date ranges. The number of Ids can number into a few thousand and because of this, we realize we cannot pass these query parameters in a GET HTTP header since there is a limit on header size.
We are starting to look into passing our query parameters into the JSON body of a POST request. For example, we could have client pass in a few thousand Ids as an array and also pass in a date range, so we'd have each query param/filter be an object. The JSON body would then be an array of objects. For example:
{
"action" : "search",
"queryParameters" : {
[
{
“operation”: “in”,
"key" : "name.of.attribute.Id",
"value" : "[{ "id: "067e6162-3b6f-4ae2-a171-2470b63dff00"}, {"id": "next id"....}],
},
{
“operation”: “greater”,
"key" : "name.of.attribute “,
"value" : "8/20/2016"
},
{
“operation”: “less”,
"key" : "name.of.attribute “,
"value" : "8/31/2016"
}
]
}
The back end code would then receive POST and read the body. It would see action is a search and then look for any entries in the list that are in the list of Ids that are in the date range of > 8/20/2016 and < 8/31/2016.
I've been trying to look online for tips/best practices on how best to structure the JSON body for complex queries but have not found much. So any tips, guidance or advice would be greatly appreciated.
thanks.

Backand Query with geo point

I am trying to build a query, and pass parameters to it,
not sure how can I do it, here is my query
{ "object": "garages", "q": { "lat_long" : { "$within" : [[28.703341,77.130605],10000] } } }
I am passing lat,lng and radios.
Now I am able to pass the params, however in response I get lat_long
as "lat_long": "AAAAAAEBAAAAVYSbjCqfPEDyzTY3pkVTQA==" .
Is it encoded / serialized? How can I'll get my original values?
Thank you,
Point is stored as a binary value, in order to see your original values you have 2 option
You can manipulate the sql statement like this :
SELECT CONCAT(X(lat_long), ',', Y(lat_long)) as origin
FROM garages WHERE (ST_Distance ..........
but this way you want be able to edit the nosql tab
When you call REST API With 'GET' on object 'garages' you'll see the values as you oroginaly Posted them

Accessing attributes of a json

I have this JSON output
{
"status":1,
"complete":1,
"list":{
"792489954":{
"item_id":"792489954",
"resolved_id":"792489954",
"given_url":"http:\/\/www.liveathos.com\/?gclid=Cj0KEQiAzb-kBRDe49qh9s75m-wBEiQATOxgwZcJ5_ws34o4PUSUYDGqs8HEbLF-LyjxrTPOwn6AYV8aAmMk8P8HAQ",
"given_title":"Athos - Wearable Technology for Fitness",
"favorite":"0",
"status":"0",
"time_added":"1418754744",
"time_updated":"1418754746",
"time_read":"0",
"time_favorited":"0",
"sort_id":0,
"resolved_title":"Wearable Technology for Fitness",
"resolved_url":"http:\/\/www.liveathos.com\/?gclid=Cj0KEQiAzb-kBRDe49qh9s75m-wBEiQATOxgwZcJ5_ws34o4PUSUYDGqs8HEbLF-LyjxrTPOwn6AYV8aAmMk8P8HAQ",
"excerpt":"Thank you for reserving Athos. You will receive a confirmation email with reservation details and a referral link where you get $10 off your next order.",
"is_article":"0",
"is_index":"0",
"has_video":"0",
"has_image":"0",
"word_count":"25"
},
"692647226":{
"item_id":"692647226",
"resolved_id":"692647226",
"given_url":"http:\/\/www.terrafugia.com\/news",
"given_title":"News | Terrafugia",
"favorite":"0",
"status":"0",
"time_added":"1418754204",
"time_updated":"1418754204",
"time_read":"0",
"time_favorited":"0",
"sort_id":1,
"resolved_title":"News",
"resolved_url":"http:\/\/www.terrafugia.com\/news",
"excerpt":"",
"is_article":"0",
"is_index":"1",
"has_video":"0",
"has_image":"0",
"word_count":"0"
},
`...etc` "since":1419641101
};
It's a JSON with a list that should have article items on it. I want to access the properties of these smaller items like given_url.
I'm using
for key in (BIGJSONRESPONSE).list
do etc...
When I try printing the key, I get only the id that comes before an item. Any idea how to access more?
Thanks!
You asked for the keys, you got the keys. To get the item associated with that key, use BIGJSONRESPONSE.list[key].
This should be correct:
for in returns the keys of an object. Since the key refers to a property of the object one can access the property using [key].
for (key in (BIGJSONRESPONSE).list)
{
console.log(BIGJSONRESPONSE.list[key]) // log the entry to console for debugger.
}