Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31162 > unrolled thread
| Started by | moogyd@yahoo.co.uk |
|---|---|
| First post | 2012-10-12 07:09 -0700 |
| Last post | 2012-10-14 22:48 -0700 |
| Articles | 7 — 6 participants |
Back to article view | Back to comp.lang.python
Basic JSON question: Do I really need the quotes moogyd@yahoo.co.uk - 2012-10-12 07:09 -0700
Re: Basic JSON question: Do I really need the quotes Kwpolska <kwpolska@gmail.com> - 2012-10-12 16:14 +0200
Re: Basic JSON question: Do I really need the quotes Roel Schroeven <roel@roelschroeven.net> - 2012-10-12 19:27 +0200
Re: Basic JSON question: Do I really need the quotes Adam Tauno Williams <awilliam@whitemice.org> - 2012-10-12 13:52 -0400
Re: Basic JSON question: Do I really need the quotes Roy Smith <roy@panix.com> - 2012-10-12 20:03 -0400
Re: Basic JSON question: Do I really need the quotes rusi <rustompmody@gmail.com> - 2012-10-12 20:30 -0700
Re: Basic JSON question: Do I really need the quotes moogyd@yahoo.co.uk - 2012-10-14 22:48 -0700
| From | moogyd@yahoo.co.uk |
|---|---|
| Date | 2012-10-12 07:09 -0700 |
| Subject | Basic JSON question: Do I really need the quotes |
| Message-ID | <cbd2f125-38ca-4f46-9077-95de0cf7ea6f@googlegroups.com> |
Hi,
I need to define some configuration in a file that will be manually created.
Internally, the data will be stored as a dict, which contains various properties related to a design
e.g. Design Name, dependencies, lists of files (and associated libraries).
json seemed a quick an easy way of achieving this
Anyway, in simple terms my question - if I know everything is a string, how can I omit the quotation marks?
i.e. I can do
>>> json.loads('{"mykey":["data0", "data1"]}')
{u'mykey': [u'data0', u'data1']}
But I would like to do
>>> json.loads('{mykey:[data0, data1]}')
Traceback (most recent call last):
The problem is that I don't want to make users have to type redundant characters.
Is it possible?
Thanks,
Steven
[toc] | [next] | [standalone]
| From | Kwpolska <kwpolska@gmail.com> |
|---|---|
| Date | 2012-10-12 16:14 +0200 |
| Message-ID | <mailman.2090.1350051279.27098.python-list@python.org> |
| In reply to | #31162 |
On Fri, Oct 12, 2012 at 4:09 PM, <moogyd@yahoo.co.uk> wrote: > Hi, > I need to define some configuration in a file that will be manually created. > Internally, the data will be stored as a dict, which contains various properties related to a design > e.g. Design Name, dependencies, lists of files (and associated libraries). > json seemed a quick an easy way of achieving this > Anyway, in simple terms my question - if I know everything is a string, how can I omit the quotation marks? Nope. JSON has those rules for a reason. You need to be specific. A more “human-friendly” format is the one used by ConfigParser (close to INI, but not quite). Also, JSON is supposed to be generated by computers, not humans. -- Kwpolska <http://kwpolska.tk> stop html mail | always bottom-post www.asciiribbon.org | www.netmeister.org/news/learn2quote.html GPG KEY: 5EAAEA16
[toc] | [prev] | [next] | [standalone]
| From | Roel Schroeven <roel@roelschroeven.net> |
|---|---|
| Date | 2012-10-12 19:27 +0200 |
| Message-ID | <mailman.2096.1350062835.27098.python-list@python.org> |
| In reply to | #31162 |
moogyd@yahoo.co.uk schreef:
> Hi,
> I need to define some configuration in a file that will be manually created.
> Internally, the data will be stored as a dict, which contains various properties related to a design
> e.g. Design Name, dependencies, lists of files (and associated libraries).
> json seemed a quick an easy way of achieving this
> Anyway, in simple terms my question - if I know everything is a string, how can I omit the quotation marks?
>
> The problem is that I don't want to make users have to type redundant characters.
> Is it possible?
Not in JSON. Maybe you could try YAML?
--
"Too often we hold fast to the cliches of our forebears. We subject all
facts to a prefabricated set of interpretations. Too often we enjoy the
comfort of opinion without the discomfort of thought."
-- John F Kennedy
roel@roelschroeven.net
[toc] | [prev] | [next] | [standalone]
| From | Adam Tauno Williams <awilliam@whitemice.org> |
|---|---|
| Date | 2012-10-12 13:52 -0400 |
| Message-ID | <mailman.2099.1350066335.27098.python-list@python.org> |
| In reply to | #31162 |
On Fri, 2012-10-12 at 19:27 +0200, Roel Schroeven wrote: > moogyd@yahoo.co.uk schreef: > > Hi, > > I need to define some configuration in a file that will be manually created. > > Internally, the data will be stored as a dict, which contains various properties related to a design > > e.g. Design Name, dependencies, lists of files (and associated libraries). > > json seemed a quick an easy way of achieving this > > Ayway, in simple terms my question - if I know everything is a string, how can I omit the quotation marks? > > The problem is that I don't want to make users have to type redundant characters. > > Is it possible? > Not in JSON. Maybe you could try YAML? If you want a human-readable human-editable markup for data structures I strongly encourage you to look at YAML. JSON is not wetware friendly.
[toc] | [prev] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2012-10-12 20:03 -0400 |
| Message-ID | <roy-6ED2F5.20034412102012@news.panix.com> |
| In reply to | #31162 |
In article <cbd2f125-38ca-4f46-9077-95de0cf7ea6f@googlegroups.com>, moogyd@yahoo.co.uk wrote: > I need to define some configuration in a file that will be manually created. > [...] > json seemed a quick an easy way of achieving this JSON would not be my first choice for a file which needs to be maintained by hand. I've only recently started using a system that has YAML config files. I've quickly become enamored of the format for config files. I don't know if it's capable of expressing everything you can with JSON, but it certainly can do anything you would reasonably want to put in a config file, it's easy to read, and easy to hand-edit. > The problem is that I don't want to make users have to type redundant > characters. I think what you're saying is, "My users would prefer YAML over JSON" :-)
[toc] | [prev] | [next] | [standalone]
| From | rusi <rustompmody@gmail.com> |
|---|---|
| Date | 2012-10-12 20:30 -0700 |
| Message-ID | <8984e448-98b8-4710-9a43-40462ac35ffa@ro10g2000pbc.googlegroups.com> |
| In reply to | #31177 |
On Oct 13, 5:03 am, Roy Smith <r...@panix.com> wrote: > In article <cbd2f125-38ca-4f46-9077-95de0cf7ea6f@googlegroups.com>, > > moo...@yahoo.co.uk wrote: > > I need to define some configuration in a file that will be manually created. > > [...] > > json seemed a quick an easy way of achieving this > > JSON would not be my first choice for a file which needs to be > maintained by hand. > > I've only recently started using a system that has YAML config files. > I've quickly become enamored of the format for config files. I don't > know if it's capable of expressing everything you can with JSON, but it > certainly can do anything you would reasonably want to put in a config > file, it's easy to read, and easy to hand-edit. Yaml is a superset of json http://en.wikipedia.org/wiki/YAML#JSON I find it a bit mysterious: yaml's structure-via-indentation philosophy makes it more in line with python than most other modern languages. And yet its the ruby community that seems to most eagerly embrace yaml. Specially ironic given that ruby's syntax is reminiscent of Pascal -- statements dont just close with '}' but with 'end'
[toc] | [prev] | [next] | [standalone]
| From | moogyd@yahoo.co.uk |
|---|---|
| Date | 2012-10-14 22:48 -0700 |
| Message-ID | <cd8fbd9e-9b0f-41ba-848c-ceaa4b7565d0@googlegroups.com> |
| In reply to | #31162 |
On Friday, 12 October 2012 16:09:14 UTC+2, (unknown) wrote:
> Hi,
>
> I need to define some configuration in a file that will be manually created.
>
> Internally, the data will be stored as a dict, which contains various properties related to a design
>
> e.g. Design Name, dependencies, lists of files (and associated libraries).
>
> json seemed a quick an easy way of achieving this
>
> Anyway, in simple terms my question - if I know everything is a string, how can I omit the quotation marks?
>
>
>
> i.e. I can do
>
>
>
> >>> json.loads('{"mykey":["data0", "data1"]}')
>
> {u'mykey': [u'data0', u'data1']}
>
>
>
> But I would like to do
>
> >>> json.loads('{mykey:[data0, data1]}')
>
> Traceback (most recent call last):
>
>
>
> The problem is that I don't want to make users have to type redundant characters.
>
> Is it possible?
>
> Thanks,
>
> Steven
Hi,
Thanks to everyone for the responses. I'll look at YAML and ConfigParser.
Steven
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web