Hi there, in my project blueprint I’m trying to use Google Natural Language APIs but can’t find a way to serialize a correct json.
I need a json like this:
{
“document”: {
“type”: “PLAIN_TEXT”,
“language”: “it”,
“content”: “domanda da analizzare”
},
“encodingType”: “UTF8”
}
Where “content” is a string type variable in my blueprint.
How can I make this JSON using VaRest to send to to the service?
But in print string i got the json like this:
{“document”:“{"type":"PLAIN_TEXT","language":"it","content":"ciao! oggi sono stato molto bene e sono molto contento"}”,“encodingType”:“UTF8”}
In the first “Print String” node the string from “Encode JSON to single string” is:
{"type":"PLAIN_TEXT","language":"it","content":"ciao, oggi sono stato molto bene e sono molto contento"}
In the second “Print String” node the string from “Encode JSON to single string” is:
{"document":"{\"type\":\"PLAIN_TEXT\",\"language\":\"it\",\"content\":\"ciao, oggi sono stato molto bene e sono molto contento\"}","encodingType":"UTF8"}
The JSON should be like this:
{
"document": {
"type": "PLAIN_TEXT",
"language": "it",
"content": "ciao, oggi sono stato molto bene e sono molto contento"
},
"encodingType": "UTF8"
}
I tried other nodes and functions but nothing is changing something so I think the problem could be in “Encode JSON to single string” node, but I am not a pro so I really don’t know.
May there is another way to setup a JSON like this with VaRest but I don’t know about it.
It seems that is not working with “decote json object”.
I tryed to clean the string replacing "" with " " but even if in “print string” I see it correctly when I try to post it to google service there are "" in the string again.
I don’t know.
Maybe I placed “decode” in the wrong position idk.
{"document":{ "type ": "PLAIN_TEXT ", "language ": "it ", "content ": "ciao, oggi sono stato molto bene e sono molto contento "},"encodingType":"UTF8"}
Google Natural Language response is:
LogVaRest: Request (json): POST https://language.googleapis.com/v1beta2/documents:analyzeSentiment?key=***** (check bExtendedLog for additional data)
LogVaRest: Response (400):
JSON(
{
"error": {
"code": 400,
"message": "Invalid value at 'document' (type.googleapis.com/google.cloud.language.v1beta2.Document), \"{\"document\":{ \"type \": \"PLAIN_TEXT \", \"language \": \"it \", \"content \": \"ciao, oggi sono stato molto bene e sono molto contento \"},\"encodingType\":\"UTF8\"}\"",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document",
"description": "Invalid value at 'document' (type.googleapis.com/google.cloud.language.v1beta2.Document), \"{\"document\":{ \"type \": \"PLAIN_TEXT \", \"language \": \"it \", \"content \": \"ciao, oggi sono stato molto bene e sono molto contento \"},\"encodingType\":\"UTF8\"}\""
}
]
}
]
}
}
)JSON