I am developing a custom terraform provider in Go.
I have a JSON parameter like this:
local_context_data = jsonencode({"hello"="world"})
When I check what is sent to the API with TCPdump I can see that the JSON is escaping like this:
{\"hello\":\"world\"}.
But it generates an error because the API is waiting for real JSON without escape.
Do we have a function in Go to unescape this?
Or better: do we have a function in the terraform SDK?
if your API expects json, what you want is probably
local_context_data = {"hello"="world"}
You only need jsonencode if you want to send a json string within the json.
Related
I have never encountered this sort of collection or object before until now (its the response from a request to Google-Cloud-Vision API).
I wrote a class that uses the API and does what I want correctly. However the only way that I can extract/manipulate data in the response is by using this module:
from google.protobuf.json_format import MessageToJson
I basically serialized the protobuff into a string and then used regex to get the data that I want.
There MUST be a better way than this. Any suggestions? I was hoping to have the API response give me a json dict or json dict of dicts etc... All I could come up with was turning the response into a string though.
Here is the file from the github repository:
image_analyzer.py
Thank you all in advance.
The built in json module will parse the string into a dictionary, like json.loads(MessageToJson(response1)).
You can just access the fields in the message object directly, e.g.:
response1 = vision_client.face_detection(image=image)
print(response1)
print(response1.face_annotations[0].detection_confidence)
I have a webhook action configured using Code Barrel's Automation for JIRA add-on. It sends a request to an endpoint that expects a JSON payload.
Using the templating syntax, I can write a custom body like
{"some_key": "{{issue.summary}}"}
to template values into the JSON payload:
However, this is fragile; if any of the templated values contain a double quote or a backslash, we're likely to generate a syntactically invalid JSON payload.
Is there any way in Automation for JIRA to escape text for inclusion within a JSON string?
I just did a quick release that enables you to encode these values. You can find the docs at - https://docs.codebarrel.io/automation/smart-fields/working-with-strings.html#encoding
Though it is pretty simple:
{"some_key": "{{issue.summary.jsonEncode}}"}
This is live in Cloud and available in version 3.9.7 in Server.
Hope that is what you were after.
I'm using the sonarQube 6.4 web api to get a list of issues
http://sonar-server:9000/api/issues/search?componentKeys=Project_key&sinceLeakPeriod=true&statuses=OPEN,REOPENED&types=BUG
This gives me a Json object which has single quotes,
..."message":"Make this function anonymous by removing its name:
'function() {...}'."...
Because of that highlighted content in the JSON I'm unable to process the JSON from Groovy.
Is the JSON returned by the sonar is valid ?
if so, is there any way to process this kind of JSON in groovy.
Let me know if the full JSON object is needed.
According to http://json.org/ and https://jsonformatter.curiousconcept.com/ the JSON response is valid. Single quotes and brackets {} must not be escaped. The issue comes from your Groovy parser.
I'm building a REST API in JAVA and C# and I was wondering about the way I should pass data to those services.
What I'm familiar with as the right way is to send JSON object as the data in the POST body:
{name:'Dor'}
but I can also pass a string and parse the JSON in my service:
'{name:'Dor'}'
What is the preferable way from performance factor? or any other factors?
Basically, if you need to send the json data across via jquery, then we need to use stringify, else the data would be serialized into to key=value pair.
So, you cannot send the json object directly via jquery ajax method.
How it works behind the hood:
In $.ajax function, if we provide data as
data :{key1:"value1", key2:"value2"}
is serialized to key1=value1&key2=value2
if we provide data as
data :'{key1:"value1", key2:"value2"}' or JSON.stringify({key1:"value1", key2:"value2"})
is sent as {key1:"value1", key2:"value2"}
So, what we can conclude is that, we cannot pass json object directly via jquery, we can send only json string. Hope this clarifies everyone.
I'm trying to execute example from here: https://developer.paypal.com/docs/classic/paypal-payments-pro/gs_PayPalPaymentsPro/
curl -s --insecure https://api-3t.sandbox.paypal.com/nvp -d "USER=platfo_1255077030_biz_api1.gmail.com&PWD=1255077037&SIGNATURE=Abg0gYcQyxQvnf2HDJkKtA-p6pqhA1k-KTYE0Gcy1diujFio4io5Vqjf&METHOD=DoDirectPayment&VERSION=78&PAYMENTACTION=SALE&AMT=5&ACCT=4660997962602322&CREDITCARDTYPE=VISA&CVV2=176&FIRSTNAME=James&LASTNAME=Smith&STREET=FirstStreet&CITY=SanJose&STATE=CA&ZIP=95131&COUNTRYCODE=US&EXPDATE=092015"
Documentation says:
Request method, format Response format
HTTP GET Name/value pairs JSON
But I receives:
TIMESTAMP=2015%2d01%2d30T12%3a14%3a08Z&CORRELATIONID=474de7dae8e82&ACK=Success&VERSION=78&BUILD=15009693&AMT=5%2e00&CURRENCYCODE=USD&AVSCODE=X&CVV2MATCH=M&TRANSACTIONID=93V64243P1844913T
Why? How to get json response?
I tried to set:
VERSION=95
but didn't help.
As document states the paypal NVP api doesn't straight away provide json response.
The way attained to process the response goes like below,
In PHP
parse_str($response,$responseArray);
$jsonResponse = json_encode($responseArray);
helped me to get the array from the response string and in turn converted to json.
Edit : you first need to decode the urlencoded string.
For that
$response = urldecode($response);
Before parsing the response to array.
While I do see the documentation you quoted (from https://developer.paypal.com/docs/classic/paypal-payments-pro/gs_PayPalPaymentsPro/), I think it's flat-out wrong.
I don't believe the classic PayPal APIs support JSON (except Adaptive Payments, which was written later # PayPal & is thus a bit more modern in some ways, including the JSON support).
See https://developer.paypal.com/docs/classic/api/gs_PayPalAPIs/, which describes the headers taht you can use to request JSON from the Adaptive APIs but clarifies that the other classic APIs don't support it.