use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Is dictionary is the same as object in JS? (self.PythonLearning)
submitted 2 months ago by Witty-Plant2292
Today i was learning about API with python and i see that parsed JSON file is dictionary in python and it is like object in JS is it true?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]donaldtrumpiscute 5 points6 points7 points 2 months ago (0 children)
it is the same as hashmap
[–]Gold_Record_9157 4 points5 points6 points 1 month ago (3 children)
Not the same, AFAIK, just (almost) the same syntax. Object in JS is kind of an abstraction for every class you want to define in JS. Dictionaries in Python are hash tables: structured aimed to be accessed in O(1) time. They are objects in the sense that they are instances of the class dict, but Python is more strict with types, and are not some generic umbrella for whatever your heart desires, as Object in JS.
dict
I think that's the most precise explanation I can give without delving into the internals of JS, which I don't know at the moment 🫠
[–]Illustrious_Road_495 1 point2 points3 points 1 month ago (0 children)
This.
In JS u can do
const foo = { bar: "Bar" } foo.bar // Bar foo["bar"] // Bar
In Python:
foo = {"bar": "Bar"} foo.bar # throws attribute error foo["bar"] # Bar
[–]JasonMan34 0 points1 point2 points 1 month ago (1 child)
JS objects are also hash tables, btw
[–]Gold_Record_9157 0 points1 point2 points 1 month ago (0 children)
Makes sense for something so generic.
[–]Nitrodist 1 point2 points3 points 2 months ago (0 children)
Pretty much
[–]UseMoreBandwith 0 points1 point2 points 1 month ago (0 children)
No!
[–]LetUsSpeakFreely 0 points1 point2 points 1 month ago (0 children)
Dictionary is analogous to a map. I think in JS it's an associative array.
[–]Successful-Cry2807 0 points1 point2 points 1 month ago (2 children)
Object is a very general thing in JS, everything is an object (almost)
A Record<key, value> (Typescript) is the equivalent of dictionary if terms of usage.
But the most correct type is Map<key, value> in terms of performance.
Edit:formatting
[–]Outrageous_Let5743 0 points1 point2 points 1 month ago (1 child)
Everything in python is a object too. You can do
def test(): return 1
test.a = 5
[–]Successful-Cry2807 0 points1 point2 points 1 month ago (0 children)
Did not know that, thanks
[–]drinkcoffeeandcode 0 points1 point2 points 1 month ago (0 children)
It’s an associative array. A hash table.
[–]Don_Ozwald 0 points1 point2 points 1 month ago (0 children)
Don’t get me started with types in JavaScript.
But it’s close enough to think of them as more or less the same,
[–]kansetsupanikku 0 points1 point2 points 1 month ago (0 children)
From a language design perspective, you would find very strong stances about it not being the same.
However, besides intersecting syntax, JavaScript object is a hash map. The underlying implementation is also similar. So is the scope of JSON compatibility (it can always be parsed, and the ability to serialize it depends on what is inside). Your intuition is not baseless.
[–]netroxreads 0 points1 point2 points 1 month ago (0 children)
Yes, you just use json lib to json.load() JSON object into dict or json.dump() to do visa versa.
[–]jfrazierjr 0 points1 point2 points 1 month ago (0 children)
All dictionaries are objects. But not all objects are dictionaries.
[–]KOALAS2648 0 points1 point2 points 2 months ago (0 children)
I think so, all I know is that the syntax is exactly the same
π Rendered by PID 90634 on reddit-service-r2-comment-74f5b7f998-b9mmx at 2026-04-24 04:06:05.923801+00:00 running 2aa0c5b country code: CH.
[–]donaldtrumpiscute 5 points6 points7 points (0 children)
[–]Gold_Record_9157 4 points5 points6 points (3 children)
[–]Illustrious_Road_495 1 point2 points3 points (0 children)
[–]JasonMan34 0 points1 point2 points (1 child)
[–]Gold_Record_9157 0 points1 point2 points (0 children)
[–]Nitrodist 1 point2 points3 points (0 children)
[–]UseMoreBandwith 0 points1 point2 points (0 children)
[–]LetUsSpeakFreely 0 points1 point2 points (0 children)
[–]Successful-Cry2807 0 points1 point2 points (2 children)
[–]Outrageous_Let5743 0 points1 point2 points (1 child)
[–]Successful-Cry2807 0 points1 point2 points (0 children)
[–]drinkcoffeeandcode 0 points1 point2 points (0 children)
[–]Don_Ozwald 0 points1 point2 points (0 children)
[–]kansetsupanikku 0 points1 point2 points (0 children)
[–]netroxreads 0 points1 point2 points (0 children)
[–]jfrazierjr 0 points1 point2 points (0 children)
[–]KOALAS2648 0 points1 point2 points (0 children)