Ember insert underscore in json-serialization - json

i have the following JSON-GET response:
{
"check_lists": [
{
"id": 2,
"name": "Servicebesuch",
"description": ""
}]
}
Problem is the "check_lists" name which i have solved in one of the extract/extractSingle methods of the RESTSerializer so the data is loaded and deserialized successfully to the model named App.Checklist.
Now i got stucked again.
For serialization of my model-data to json, i have to do the same trick reverse but i can not find a hook for that. The serialize Method of the RESTSerializer gets only the pure record and the serialized json, received from this._super... call, does only hold the serialized object and not the call itself.
The server expects a PUT request (in case of updating a list) with the parameter packed in a param named check_list but ember sends it in a param named checklist.
Processing by CheckListsController#update as JSON
Parameters: {"checklist"=>{"name"=>"Kaffeevertrieb", "description"=>""},
"id"=>"3", "check_list"=>{}}
ActionController::ParameterMissing (param is missing or the value is empty: check_list):
Does someone know how to insert the underscore to the json request?
Greetings

Related

Passing json string as an input to one of the parameters of a POST request body

I need to pass a json string as a value to one parameter of a POST request body. My request body looks like this:
"parameter1":"abc",
"parameter2":"def",
"parameter3": "{\"id\":\"\",\"key1\":\"test123\",\"prod1\":{\"id\":\"\",\"key3\":\"test123\",\"key4\":\"12334\",\"key5\":\"3\",\"key6\":\"234334\"},\"prod2\":{\"id\":\"\",\"key7\":\"test234\",\"key8\":1,\"key9\":true}}\"",
"parameter4":false,
"parameter5":"ghi"
}
For parameter3 I need to be pass a string value in json format. The json file is located in my local system and is a huge file, so it would make sense if I can pass it as a jmeter variable. I tried as below:
{
"parameter1":"abc",
"parameter2":"def",
"parameter3": "${jsonObj}",
"parameter4":false,
"parameter5":"ghi"
}
after adding a JSR223 preprocessor with the code below:
import org.apache.jmeter.util.JMeterUtils;
String fileContents = new File("path to json//myJson.json").getText('UTF-8');
vars.put("fileContents",fileContents);
var deltaJson = vars.get("fileContents");
var jsonObj = JSON.parse(deltaJson);
vars.put("jsonObj", JSON.stringify(jsonObj));
But I get below error:
exceptions":{"exceptionType":"System.JSONException","exceptionMessage":"Unexpected character ('$' (code 36)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]"}
Can anyone help me in resolving this issue?
There is an easier way of doing this, JMeter comes with __FileToString() function so you can achieve the same much faster and without having to do any scripting
Something like:
{
"parameter1": "abc",
"parameter2": "def",
"parameter3": ${__FileToString(path to json//myJson.json,UTF-8,jsonObj)},
"parameter4": false,
"parameter5": "ghi"
}
Also be aware of the following facts:
the recommended language for using in JSR223 Test Elements is Groovy as it provides the maximum performance
you seem to be using JSON object which cannot be used outside of the browser context therefore your code fails to generate proper JSON hence your request fails as you're passing ${jsonObj} as it is, the substitution doesn't happen, you can look to jmeter.log file yourself and see the exact reason of your script failure

Unable to get a key value called properties "properties": "Value" Groovy

I'm making API requests to a service which returns a JSON object within the body.
I can't seem to get the value of a key called "properties" within groovy.
Everytime I call obj.properties i get the following back
{
"class": "org.json.JSONObject"
}
but if I call just the obj I get the expected JSON object
{
"dummy1": ,
"dummy2": false,
"dummy3": etsad,
"dummy4": asdfw,
"dummy5": qweqwe,
"dummy6": 123123,
"properties": {
"country": UK,
}
}
Likewise if I obj.dummy2 i get false it's only when I obj.properties do I get the above mentioned response
Notice groovy have a special handling for Object's properties, for example for number:
def y = 25
print y.properties
It will print [class:class java.lang.Integer]
So it's part of basic groovy object
See also an answer about getting non-synthetic properties from groovy object
As #daggett comment, you can use
obj.get('properties')
Check out this answer here on how to access the properties of objects.
The reason obj.properties isn't working is most likely due to the fact that every object will have properties, and in your case obj.properties is getting the properties of the JSON object and not the value associated with the key.
Instead of obj.properties, consider obj['properties']

How to define schema arbitrary JSON object?

I am trying to define a API using OAS v2 that will return a payload along with some metadata.
In other words, the response to the API will be:
{
"metadata":[
{
"key" :"key1",
"value": "value1"
}
],
"payload": {Valid JSON}
}
The payload can be anything, and different for different scenarios, the only constraint being it will be a valid JSON format. So, at this point in time, I would like to define it just as a JSON object without defining the field level details.
How can I do that in OAS2/JSON schema?
Thanks in advance.
In this case you can use an empty schema ({}) for payload.
JSON Schema relies on valid JSON value and you won't be able to supply it if your response is a malformed JSON.
If payload value is malformed, whole response will not be a valid JSON.
In other words, this issue is out of JSON Schema scope, but rather in scope of your response decoder (that should fail on malformed response body).

Azure Logic App - JSON to XML Conversion - function #xml()

Passing a valid JSON Message to the #xml() function works but the output seems to be somehow serialized. Is there a reference how to use the #xml() function or does anybody know what i'm doing wrong?
Expression in Data Operations - Compose Function (where 'Add_Root_Element' is the previous Function Block):
"inputs": {
"xml": "#xml(outputs('Add_Root_Element'))"
}
Generated Output:
{
"xml": {
"$content-type": "application/xml;charset=utf-8",
"$content": "PHJvb3Q+PHBhcnRpY2lwYW50Pjxjb3VudHJ5PkF1c3RyYWxpYTwvY291bnRyeT48ZGVwYXJ0bWVudD5JbmZvcm1hdGlvbiBUZWN...
}
}
This question relates to the following question: Azure Logic App - JSON to XML Conversion
The xml function returns a Base 64 string, if you take that $content value and transforms from Base 64 to string, you will obtain the generated XML.
A simple proof of concept is generate an HTTP Request - Response Logic App, that receives a JSON and in the output you assign to de body #xml(triggerBody()).
When you call, you will see in the output the XML representation of your input.

Backbone.js .save() JSON response attribute issue

So my issue is this.
Using backbone to save something in a MYSQL Database.
When I call this.model.save() I am getting a very weird issue.
The model will save the JSON response as an object and will not update the new values instead.
So my attributes in development tools will look something like this.
attributes: Object
0: Object
ID: "4"
Name: "TEST"
Title: "MEOW"
Stuff: "1"
When: "2013-02-14 22:17:14"
The 0 should not be there. I did confirm that the json object is valid so I know that is not the issue here.
It looks like your JSON response is actually an array with a single element, not an object.
The property 0 is created when Backbone calls model.set(response), which in turn copies all keys of the response object to the attributes hash. If an array is passed to set, this is what happens.
You should fix your server to respond with a raw object ({...}) instead of an array ([{...}]). If you're not able to change the server behaviour, you can override Model.parse to unwrap the response on the client:
var Model = Backbone.Model.extend({
parse: function(response) {
return _.isArray(response) ? response[0] : response;
}
});