N
N
Nikolay Baranenko2017-07-26 15:28:29
Python
Nikolay Baranenko, 2017-07-26 15:28:29

Why is the error being reproduced that the 'json' module does not have a 'dumps' attribute?

Hello.
There was a need in python to work with JSON,
the code is below

#!/usr/bin/python
import json

part_nums = ['ECA-1EHG102','CL05B103KB5NNNC','CC0402KRX5R8BB104']

def json_list(list):
    lst = []
    for pn in list:
        d = {}
        d['mpn']=pn
        lst.append(d)
    return json.dumps(lst)

print(json_list(part_nums))

an error occurs
AttributeError: module 'json' has no attribute 'dumps'

The question is why and how to solve it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolay Baranenko, 2017-07-26
@drno-reg

I rolled up the simplejson module,
as a result it will turn out something like this

#!/usr/bin/python
import simplejson as json

part_nums = ['ECA-1EHG102','CL05B103KB5NNNC','CC0402KRX5R8BB104']

def json_list(list):
    lst = []
    for pn in list:
        d = {}
        d['mpn']=pn
        lst.append(d)
    return json.dumps(lst)

print(json_list(part_nums))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question