How do I delete a JSON Object key from the D JSON type? - d

The documentation doesn't have myjson.remove(key) or similar.
How would I delete a key from a json object without recreating the json object?

You can do so by accessing the internal object:
myjson.object.remove(key);

Related

return id if get_or_created inserts data, django

maybe it's simple question to ask but couldn't figure out how. I am inserting data with get_or_created and if there is a insert then trying to return that row's ID. To achieve this I tried like it below.
obj, created = Advertisements.objects.get_or_create(budgets_id=pid, ad_brand=ad_brand, ad_kind=ad_kind, saved_date=today)
print(created.id)
even if there is an insert. it returns an error. what is the right way to get an ID in this kind of situation.
'bool' object has no attribute 'id'
Watch get_or_create() docs
Returns a tuple of (object, created), where object is the retrieved or
created object and created is a boolean specifying whether a new
object was created.
You need to call print(obj.id)

QJsonObject how to create function

I know how to create members and values in a QJsonObject. What I want to do is create a Json function that when called will call the assigned function.
Is this possible?
I think that is not possible, functions are not a valid json value.
Valid json values are : string, number, object, array, boolean or null.
In Qt, valid QJsonValues are: bool QJsonValue::Bool, QJsonValue::Double, QJsonValue::String, QJsonValue::Array, QJsonValue::Object, QJsonValue::Null
json spec

Amazon S3: How to get object size and lastmodified by key?

I found only one way to get object size and last modified: it is client.ListObjects() method. But it can returns multiple files by prefix. For example:
a.txt
a.txt.bak
What is right way to retrieve object size by key?
Are you sure you're correctly inspecting the response? As per the docs (http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listObjects-property) the size is returned.
UPDATE (since I did't fully understand the question):
I think headObject is what you're looking for: it takes a key and returns metadata of an object. Look at LastModified and ContentLength in the response.

set Doctrine2 entity property without retrieving entire associated object

I have a table Object that has 2 fields that are foreign keys (user_id and teacher_id). After generating the Entities for the X table, the entity only contain the $user and $teacher properties, which forces me to use the associated objects instead of id. So supposing I know the user_id and teacher_id for my object, instead of doing:
$object->setUserId(1)
I have to do:
$user = $this->getDoctrine()->getRepository('MyBundle:Users')->find(2);
$object->setUser($user)
is there no way to work directly with the ids to avoid retrieving the entire object associated to each id?
The framework suggests to use objects when setting the association value. Still – are you sure the record isn't loaded in the memory already? If it is, it will not cause additional SQL statement execution.
If you really need to update the association without loading the object, you can
run native SQL;
try creating Doctrine Proxy object manually and setting it instead.
You can get the proxy object using EntityManager method getReference:
$object->setUser($this->getDoctrine()->getReference('MyBundle:Users', 2));

Deserialize django json data dump one record at the time?

I`m trying to read a file with json-data, use the loads(data) simplejson method and extract create a dictionary representing the values for each column in a record, instead of using the "standard" or documented way of :
for obj in serializers.deserialize("json", data):
# do something with obj
because I want to avoid creating django orm objects for each record, I just want a dictionary representing each object so I can insert that into the database using plain SQL for gain speed. The problem is that loads(data) needs to read all the data into memory and I want to avoid that to keep memory usage low and read entry for entry in the json-data. Is it possible to get an iterator that yields data for one record? And secondly, can I skip the entire creation of django orm objects when deserializing the json data and just get a dictionary of the values?
Input and thoughts are welcome.
Thanks for your time.
If you don't want to create the ORM objects, there's no point in using the Django deserialization methods. Simply load the JSON using the underlying simplejson library:
from django.utils import simplejson
my_data = simplejson.loads(data)