Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8946743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:35:15+00:00 2026-06-15T12:35:15+00:00

In Fedora 17 64bit while using netifaces and json imports. I’m trying to get

  • 0

In Fedora 17 64bit while using netifaces and json imports.

I’m trying to get this format in JSON

"net_info" : [
            {"nic" : ..., "mac" : ..., "ip" : ...},
            {"nic" : ..., "mac" : ..., "ip" : ...},
            {"nic" : ..., "mac" : ..., "ip" : ...},
            ]

I’m currently using a string and just appending to it, and I get this:

"'net_info': [{'nic':eth0,'mac':6c:f0:49:0f:e1:c2,'ip':192.168.1.116},]"

This may not work due to the quotes at the beginning and the end of each string; is there a better way of accomplishing this? I was thinking of using a List of Dictionaries but ended up trying strings first, not sure what would best in this case.

Here’s my code that takes in 3 lists:

def json_serialize(ip=[],mac=[],nic=[]):
    jsonDump = "'net_info': ["
    for i,item in enumerate(ip):
        jsonDump += "{'interface_name':" + nic[i] +",'mac':" 
                      + mac[i] + ",'ip':" + ip[i] +"},"
        jsonDump += "]"
        print jsonDump.strip()

    #Testing output after its passed in to json.dumps(), it now has quotes at beginning
    #and end of string...?
    print "\n"
    print     json.dumps(jsonDump)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:35:16+00:00Added an answer on June 15, 2026 at 12:35 pm

    Just create a python dict with a contained list instead, then dump that to JSON in one go:

    def json_serialize(ip, mac, nic):
        net_info = []
        for ipaddr, macaddr, nicname in zip(ip, mac, nic):
            net_info.append({
                'interface_name': nicaddr,
                'mac': macaddr,
                'ip': ipaddr
            })
        return json.dumps({'net_info': net_info})
    

    Your desired output format seems to be missing the outer { and } brackets to mark it a proper JSON object. If you really have to produce that output (so missing those brackets), just remove them again:

    print json_serialize(ip, mac, nic)[1:-1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Fedora 15 64bit and python 2.7 When I run python test.py from
Hi I am using 64bit Fedora 10 linux. I have created a sample java
Trying to test selenium/webdriver, running ff8/fedora 13/64bit. Trying to do a simple test of
I have recently installed Fedora 16 and I am trying to get ADT up
I installed Vim in Fedora 16 with this command: $ yum -y install vim-enhanced
I am using fedora , Unfortunately i had downloaded a package(for example 'selenium' or
Seen with gdb on openSUSE, CentOS, Fedora, and Ubuntu: This gdb was configured as
I have installed Fedora 14 on Windows XP using VMware with NAT as ethernet
I am using fedora/mozilla for my development enviorment. I am using margin: 0 auto;
I am using Fedora linux where ulimit -n 10000 increases file limit upto 10000.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.