I have been looking at the Google Sheets API v4 API. I noticed that it was JSON, but when I copied it into my IDE, I got errors because it used "primatives" such as string , number, enum(...), and object(...). JSON doesn't support these; therefore it isn't pure JSON.
After some research, I determined that it was JSON Schema; however, that must not be fully what the following code snippet it as JSON Schema doesn't seem to support object(...) and enum(...)
So what form of JSON Schema is this? I am unable to identify beyond JSON Schema.
{
"spreadsheetId": string,
"properties": {
object(SpreadsheetProperties)
},
"sheets": [
{
object(Sheet)
}
],
"namedRanges": [
{
object(NamedRange)
}
],
"spreadsheetUrl": string,
"developerMetadata": [
{
object(DeveloperMetadata)
}
]
}
Here is what NamedRange is...
{
"namedRangeId": string,
"name": string,
"range": {
object(GridRange)
}
}
Related
Is there any way to access properties of an object that was transformed into JSON through the jp (JSON parse) filter of Dust.js?
{
"response": {
"services": [
"{
\"prop1\":\"value1\",
\"prop2\":\"value2\",
\"prop3\":10
}"
]
}
}
For example, with the input above, I intend to receive the following output:
[
{
"prop1": "value1"
}
]
Note that the values inside the service array are strings, and because of that, before accessing the object's properties, I need to run JSON parse filter.
[
{#response.services}
{
"prop1": "{.|jp}"
}{#sep}, {/sep}
{/response.services}
]
What I've developed so far is the code above, and this code is returning the following output:
[
{
"prop1": "[object Object]"
}
]
In short, what I need to do is increment this {.|jp} into something where I can access the properties of the returned object, without adding new filters.
Thanks in advance to everyone who is willing to help!
I'm trying to write a webhook in Go for Dialogflow, I'm using the apiv2 of the official SDK
google.golang.org/genproto/googleapis/cloud/dialogflow/v2
But I can't generate a correct response using the official sdk.
What I mean is that following the documentation and the WebhookResponse struct I can't generate the expected json for the response.
This is the piece of code that I'm using:
response = dialogflow.WebhookResponse{
FulfillmentMessages: []*dialogflow.Intent_Message{
{
Message: &dialogflow.Intent_Message_Card_{
Card: &dialogflow.Intent_Message_Card{
Title: "Title",
Subtitle: "Subtitle",
ImageUri: "https://example.com/images/example.png",
Buttons: []*dialogflow.Intent_Message_Card_Button{
{
Text: "Button",
Postback: "https://example.com/path/for/end-user/to/follow",
},
},
},
},
},
},
}
This is the json that it generates:
{
"fulfillment_messages": [
{
"Message": {
"Card": {
"title": "Title",
"subtitle": "Subtitle",
"image_uri": "https://example.com/images/example.png",
"buttons": [
{
"text": "Button",
"postback": "https://example.com/path/for/end-user/to/follow"
}
]
}
}
}
]
}
But this is the json that I should send back (according to the official documentation)
"fulfillmentMessages": [
{
"card": {
"title": "card title",
"subtitle": "card text",
"imageUri": "https://example.com/images/example.png",
"buttons": [
{
"text": "button text",
"postback": "https://example.com/path/for/end-user/to/follow"
}
]
}
}
]
}
So my json doesn't work, because it has the Message that shouldn't be there, and Card with uppercase first letter. I've tried to send the json of the documentation and it works, Dialog Flow responds correctly.
I don't understand how to generate the correct json using the official SDK. Please consider that I'm pretty new using Go Lang. This is my first project.
This is the documentation that I'm using at the moment:
https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/dialogflow/v2?tab=doc#WebhookResponse
As you can see the FulfillmentMessages is an array of Intent_Message
FulfillmentMessages []*Intent_Message
And the Intent_Message has to contain Message (here the documentation)
Thanks in advance for any help and suggestions.
H2K
UPDATE:
if I use log.Println(response) I can see the correct response inside the log
fulfillment_messages:{card:{title:"Title" subtitle:"Subtitle" image_uri:"https://example.com/images/example.png" buttons:{text:"Button" postback:"https://example.com/path/for/end-user/to/follow"}}}
It is not a JSON but the structure is correct, no Message, no Card...
So the problem is when I return it with Gin and the command:
c.JSON(200, response)
I've found a solution!
I need to use the jsonpb marshaler and return it as string with Gin
Here an example:
m := jsonpb.Marshaler{}
result, _ := m.MarshalToString(response)
c.String(200, result)
I've totally went crazy on it, I hope that it could be helpful for someone else.
I need to access and change the a boolean parameter 'SELECTED' of a json object inside a json array using ember set method, but when i tried it I got error message "Assertion Failed: Cannot call set with 'false' key".
Also tried to access the data using a temp Object.
structure of JSON Array:
[
{
"VALUE":
[
{
"SELECTED":false,
"KEY":"audit_actions_added",
"NAME":"ADDED"
},
{
"SELECTED":false,
"KEY":"audit_actions_deleted",
"NAME":"DELETED"
},
{ "SELECTED":false,
"KEY":"audit_actions_disabled",
"NAME":"DISABLED"
},
{
"SELECTED":false,
"KEY":"audit_actions_enabled",
"NAME":"ENABLED"
},
{
"SELECTED":false,
"KEY":"audit_actions_modified",
"NAME":"MODIFIED"
}
],
"KEY":"",
"NAME":"",
"SELECTED":false
},
{
"VALUE":
[
{
"SELECTED":false,
"KEY":"audit_actions_deleted",
"NAME":"DELETED"
}
],
"KEY":"",
"NAME":"",
"SELECTED":false
},
{
"VALUE":
[
{
"SELECTED":false,
"KEY":"audit_actions_added",
"NAME":"ADDED"
},
{
"SELECTED":false,
"KEY":"audit_actions_deleted",
"NAME":"DELETED"
},
{
"SELECTED":false,
"KEY":"audit_actions_disabled",
"NAME":"DISABLED"
},
{
"SELECTED":false,
"KEY":"audit_actions_enabled",
"NAME":"ENABLED"
},
{
"SELECTED":false,
"KEY":"audit_actions_updated",
"NAME":"UPDATED"
}
],
"KEY":"",
"NAME":"",
"SELECTED":false
}
]
I can get the values but can't change those in ember.
Answer:
I solved it, the problem was I tried to set a parameter of a JSON Object of a JSON Array using ember set method, which in ember by default takes the value of parameter not the key, to overcome the issue I started using JSON Array.replace method of ember by making a copy of the JSON Object and changing the parameter which I need to change and replace the JSON Object itself in the JSON Array. Now it works fine.
I solved it, the problem was I tried to set a parameter of a JSON Object of a JSON Array using ember set method, which in ember by default takes the value of parameter not the key, to overcome the issue I started using JSON Array.replace method of ember by making a copy of the JSON Object and changing the parameter which I need to change and replace the JSON Object itself in the JSON Array. Now it works fine.
supposing the json body returned from a call contains some dynamic keys ie
{
"message": "search results matching criteria",
"permission": {
"261ef70e-0a95-4967-b078-81e657e32699": {
"device": {
"read:own": [
"*"
]
},
"account": {
"read:own": [
"*"
]
},
"user": {
"read:own": [
"*"
]
}
}
}
I can validate the json as follows easily enough although I am having a lot of trouble working out how to validate the objects BELOW the dynamic guid level of the response.
pm.test("response body to have correct items", function () {
pm.expect(jsonData.message).to.eq("search results matching criteria");
pm.expect(jsonData).to.have.property('permission');
pm.expect(jsonData.permission).to.have.property(pm.variables.get("otherUserId"));
});
Would ideally like to verify the device and account and user levels of the object.
Anyone with some tips?
I've tried a few ways to try and reference the otherUserId variable but nothing is working. It is either not resolving the variable therefore failing the test as its looking for a level in the json called otherUserId or it fails to run the test due to a syntax error.
This works:
pm.expect(jsonData.permission[pm.variables.get("otherUserId")]).to.have.property('device');
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: