Select values from a json that are not equal with something in python

python json.dumps double quotes
json.dumps python
python json dump to file
python json dumps pretty
python json loader
json.dump example
python string to json
python object to json

I have the following code

import json

x= [{'name': 'a', 'payment': '$10'}, {'name': 'b', 'payment': '$15'}, {'name': 'c', 'payment': '$0'}] 

y = json.dumps(x)

I would like to select all the values that don't have the value $0 and print them, like this

[{"name": "a", "payment": "$10"}, {"name": "b", "payment": "$15"}]

How can I do that?

You can use list comprehension:

x_filtered = [i for i in x if i['payment'] != '$0']

You can use a functional approach:

x_filtered = list(filter(lambda i: i['payment'] != '$0', x))

Or the good ol' fashioned for loop:

x_filtered = []
for i in x:
    if i['payment'] != '$0':
        x_filtered.append(i)

19.2. json — JSON encoder and decoder — Python 3.4.10 , The json module always produces str objects, not bytes objects. into JSON and then back into a dictionary, the dictionary may not equal the original one. output;; Repeated names within an object are accepted, and only the value of the last� dicts are equal if: 1) all keys are equal, 2) all values are equal; lists are equal if: all items are equal and in the same order; primitives are equal if a == b; Because you're dealing with json, you'll have standard python types: dict, list, etc., so you can do hard type checking if type(obj) == 'dict':, etc. Rough example (not tested):

for d in x:
    if d['payment']=='$0':
        continue
    print(d)

if you need them in a list before printing them just create a list beforehand and append the dictionaries to it instead of directly printing them out

18.2. json — JSON encoder and decoder — Python 2.7.18 , json exposes an API familiar to users of the standard library marshal JSON and then back into a dictionary, the dictionary may not equal the original one. Repeated names within an object are accepted, and only the value� In this tutorial you'll learn how to read and write JSON-encoded data using Python. You'll see hands-on examples of working with Python's built-in "json" module all the way up to encoding and decoding custom objects.

You could just use a simple list comprehension

>>> x
[{'name': 'a', 'payment': '$10'}, {'name': 'b', 'payment': '$15'}, {'name': 'c', 'payment': '$0'}]
>>> [y for y in x if y['payment'] != '$0']
[{'name': 'a', 'payment': '$10'}, {'name': 'b', 'payment': '$15'}]

Filter Expressions — JMESPath 0.7.1 documentation, For example, given the data above, select the value key from all objects Two JSON objects are equal if they have the same set of keys (for each string, the expression results in null, so the first element is not included in the result list. This might be useful if you can combine this with something that can� A step-by-step Python code example that shows how to select rows from a Pandas DataFrame based on a column's values. Provided by Data Interview Questions, a mailing list for coding and data interview problems.

SQL Not Equal Operator introduction and examples, This article explores the SQL Not Equal comparison operator () along with its usage scenarios. We use these operators to compare different values based on the conditions. Select * from dbo.products where ProductID <> 1 Cursors ( 9); DDL (7); DML (4); JSON (12); PowerShell (64); Python (21); R (9)� In the table above, we can see that there are two operators for Not Equal (<> and !=) . In this article, we will explore both operators and differences in these as well. SQL Not Equal <> Comparison Operator. We use SQL Not Equal comparison operator (<>) to compare two expressions.

How to evaluate Expressions in JsonPath using Logical Operators, Not equal to (!=) operator in JsonPath. When we want to exclude a particular set of values based on a condition we use the not equal to operator. However, values that are not hashable, that is, values containing lists, dictionaries or other mutable types (that are compared by value rather than by object identity) may not be used as keys. Numeric types used for keys obey the normal rules for numeric comparison: if two numbers compare equal (such as 1 and 1.0 ) then they can be used

MySQL 8.0 Reference Manual :: 12.3.2 Comparison , NOT IN(), Whether a value is not within a set of values Equal: mysql> SELECT 1 = 0; -> 0 mysql> SELECT '0' = 0; -> 1 mysql> SELECT '0.0' = 0; -> 1 is needed for the values in the IN() list, they are all non- JSON constants of the same type,� The example above prints a JSON string, but it is not very easy to read, with no indentations and line breaks. The json.dumps() method has parameters to make it easier to read the result: Example