T
T
TimkaTV2015-03-16 22:00:43
Python
TimkaTV, 2015-03-16 22:00:43

How to determine the number of objects in python json?

Good afternoon! How to determine the number of objects in a json string using the standard library.
For example, there are only 2 below.
{
"firstName": "Ivan",
"lastName": "Ivanov",
}
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
un1t, 2015-03-16
@TimkaTV

d = {'a':1, 'b':2}
len(d)

If this is a string, and not objects, then first you need to parse json
s = "{'a':1}"
import json
d = json.loads(s)
len(d)

V
Vladimir Abramov, 2015-03-16
@kivsiak

If the json structure is always like this then inputString.count('": "')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question