-1

i want to remove the json data from the list based on the allocation.If allocation:True then, that particular josn should remove from the dictionary. in the below data {"paperWidth": "4","allocation": True,"model": "RB3150","connType": ["Lan","Wifi","BlueTooth"],"commandSet": "TVSPOS"}

so this should remove from my final object.How to do this in python.

d = {"allPrinters": [{"models": [{"paperWidth": "4","allocation": True,"model": "RB3150","connType": ["Lan","Wifi","BlueTooth"],"commandSet": "TVSPOS"},{"paperWidth": "4","allocation": False,"model": "RB3151","connType": ["Lan","Wifi"],"commandSet": "TVSPOS"}],"active": True,"make": "TVS","_id": "59e6f670f532eb1260b50cd9"},{"models": [{"paperWidth": "4","allocation": False,"model": "EP3160","connType": ["Lan","Wifi"],"commandSet": "ESCPOS"},{"paperWidth": "4","allocation": True,"model": "EP3161","connType": ["Lan"],"commandSet": "ESCPOS"}],"active": True,"make": "EPSON","_id": "59e6fc8ff532eb1260b50cf4"}]}

Thank You, Ramesh M

2

1 Answer 1

1

I'm not sure if the thing you want to remove is the whole printer or just the model, but this should work for the former case and is simple to convert to the latter (dump the continue and replace d['allPrinters'] with model):

for i, printer in enumerate(d['allPrinters']):
     for model in printer['models']:
         if model['allocation']:
             d['allPrinters'].pop(i)
             continue
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.