0

I am trying to write a program which can create an output in JSON format, how would be best way of doing this? and programming languages?

This is an example output of JSON (expected output) which I need to input in the Name, Gender, Qualification and other attributes in a user friendly way during the execution of script. And in which outputs in following JSON format. Sorry, I am new in programming, but so much interested to learn Perl (or) Python (or) Java. What could be the best here?

Any suggestions?

P.S Sorry I am quite new to JSON as well, please apologize me for this basic one.

[
    {
        "Name":"Steven Mark",
        "gender":"male",
        "Qualification": {
            "college":"Bachelor in Science",
            "tech":"certified pro"
        },
        "contributions": [
            {
                "name":"biography",
                "type":"book",
            },
       ]
    },
    {
        "Name":"Andrea Mark",
        "Gender":"female",
        "Qualifications": {
            "college":"Bachelor in physics",
        },
        "contributions": [
            {
                "name":"my insights",
                "type":"movie",
            },
        ]
    }
]
ikegami
  • 367,544
  • 15
  • 269
  • 518
user3331975
  • 2,647
  • 7
  • 28
  • 30
  • You need to decide at least which language you're going to use first; without that decision (which is yours to make), this question is too broad to answer. – Adrian Wragg Oct 27 '14 at 08:50
  • That's not valid JSON. Learn to indent properly to find mistakes – ikegami Oct 27 '14 at 10:30

3 Answers3

2

Virtually every language has a JSON library, including Perl.

use JSON;

my $data = [
    {
        "Name" => "Steven Mark",
        "gender" => "male",
        "Qualification" => {
            "college" => "Bachelor in Science",
            "tech" => "certified pro"
        },
        "contributions" => [
            {
                "name" => "biography",
                "type" => "book",
            },
       ]
    },
    {
        "Name" => "Andrea Mark",
        "Gender" => "female",
        "Qualifications" => {
            "college" => "Bachelor in physics",
        },
        "contributions" => [
            {
                "name" => "my insights",
                "type" => "movie",
            },
        ]
    }
];

print(encode_json($data));
ikegami
  • 367,544
  • 15
  • 269
  • 518
0

If you agree to use ANY programming language, i can suggest python. With its json lib you can do following (lines with # is comments):

# import lib
import json
# fill data into variable (this is list with dict objects inside):
data = [{"name":"john"},{"name": "bill"}]
# dump json
json.dumps(data)

Which will output your data as json. You can start writing python using something from https://wiki.python.org/moin/BeginnersGuide

Michael Plakhov
  • 2,292
  • 2
  • 19
  • 21
0

If you are going to use Python, you can try to use simplejson or json module to create a json object.

For example,

try:
    import simplejson
except:
    import json

data = dict(a=1,b=2)
with open("results.json", "w") as fp:
    json.dump(data, fp, indent=3, encoding="utf-8")

For dumping, json is faster than simplejson (but not by an order of magnitude). For loading, simplejson is faster (but not by an order of magnitude).

You can check here for more detailed comparison between simplejson and json.

Community
  • 1
  • 1
Eric
  • 2,636
  • 21
  • 25