How can I send part of JSON string between AS3 and nodejs - json

I have JSON string that I get from AS3, and I need to send part of it, for example:
{"player": "player", "x_accel": "10", "y_accel": "10"}
And I want to send only x_accel, because that was the only thing that changed.

Use a Backbone Model. From Backbone Model.save doc:
"If instead, you'd only like the changed attributes to be sent to the server, call model.save(attrs, {patch: true}). You'll get an HTTP PATCH request to the server with just the passed-in attributes."

Related

Angular 2 , Node js : pass json object in url

I am using angular 2 as front end frame work and node js in the back end, So I am trying to send image with a json object that contains some particular information about that image. So I am wondering , if it is safe to pass that json object in the URL.
No, it's not safe, as your JSON object might be very long, too long for a URL. You will need to send an AJAX request where your JSON will be a parameter. Example of asynchronous request sending a JSON object:
xhttp.open("POST", "ajax_test.asp", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("data=" + JSON.stringify(yourobject));
then, on the server you will have a POST parameter called data where you will have everything you need.

How to update json field in Firebase DB with JMeter HTTP Request

I'm working with JMeter to make some HTTP Requests to my Firebase Database. I am able to create json data with a regular request, as well as with a CSV file. I'm wondering if it's possible to update, or add to, a json object.
My json data looks something like what is below. Let's say I wanted to add a boolean node called "sold", to which I could make equal to true or false. Could I create it within that json object? If so, could I also make it so that only fields with a specific "name" get updated?
{
"Price": "5.00",
"name": "buyer#gmail.com",
"seller_name": "seller#gmail.com",
"time": 1496893589683,
}
Looking into Updating Data with PATCH chapter of Saving Data article you can update a single field using HTTP PATCH Method.
JMeter supports HTTP PATCH method since version 2.8 so you should be in a position to use it as well in your test.

Pass JSON object vs JSON string in HTTP POST

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.

Grails Access JSON properties from request that don't map to specific Domain

Grails 2.4.2
I have a UserController and in its save method, I need to pass in an Organization ID along with the User data so that I can find the Organization and then create the many-to-many relationship. So I have something like this...
def save(User user) {
def orgExternalId = request.JSON.orgExternalId
userService.save(user, orgExternalId)
// more boilerplate
}
I'm POST'ing the following json:
{
"orgExternalId" : "123445",
"firstName": "gregg",
"lastName": "bolinger",
"username": "gdboling"
}
However, I'm not getting the orgExternalId out of the JSON in my controller. Also, if I inspect the JSON, it is empty, but the User domain is populated correctly. My assumption at this point is I'm going to have to use a Command Object or I could put the orgExternalId in the header, but I'd like to know if there is another way.
Have a look at Binding The Request Body To Command Objects. Mainly:
Note that the body of the request is being parsed to make that work.
Any attempt to read the body of the request after that will fail since
the corresponding input stream will be empty. The controller action
can either use a command object or it can parse the body of the
request on its own (either directly, or by referring to something like
request.JSON), but cannot do both.
I wasn't sure if I would find this verbiage while adding answer as a comment. :)

How to send JSON data in an Ajax request?

what would be the best way to send string (unicode text) & array-of-string data (several hundreds characters, for now formatted as a single Json object) from an HTML page to a PHP server document (to be then recorded in a db)? I'm pretty much new at Json and I'm not sure how to send a Json object server side with an Ajax call.
Right now, my idea would be to somehow serialize my Json object into a string, then send that string as a parameter to a POST Ajax call, but again, I'm not sure if this is the right way or how to serialize Json.
I don't use jquery at this time.
You can use JSON.stringify as you suggested.
JSON.stringify
But why do you want to serialize as JSON on the client side as opposed to sending as is to the server and converting to JSON on the server side? Then you could use a JSON library in whatever language your server supports.