Giter Club home page Giter Club logo

demjson's People

Contributors

dmeranda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

demjson's Issues

enum encode error:

    def encode_enum(self, val, state):
        """Encode a Python Enum value into JSON."""
        eas = self.options.encode_enum_as
        if eas == 'qname':
            self.encode_string( str(obj), state )
        elif eas == 'value':
            self._do_encode( obj.value, state )
        else:  # eas == 'name'
            self.encode_string( obj.name, state )

the param name is in trouble

To support numpy?

Would you support numpy to json ?
this is a common problem , and then I have not found a good solution

Unit test failure in 32-bit version of Python 2.x

When running the included unit test suite, a failure is reported if running within a 32-bit version of Python 2.x. This is because a 64-bit integer value is represented with the "L" suffix in that Python environment and the unit tests are not expecting such a suffix.

This only affects the unit tests, and not the operation of demjson or jsonlint itself.

Code bug?

hello,
I installed and tried to import demjson, but a python Error raised:

Traceback (most recent call last):
File "", line 1, in
File "/ifs1/Reotech/user/pengguoyu/software/demjson-2.2.4/demjson.py", line 645
class json_int( (1L).class ): # Have to specify base this way to satisfy 2to3
-----------------^
SyntaxError: invalid syntax

I don't know why this syntax error. My python version is:
Python 3.6.5

error in demjson setup command: use_2to3 is invalid.

When i am trying to install manually by cloning git, It was showing this:
error in demjson setup command: use_2to3 is invalid.
when i am using pip, it was howing this:

Collecting demjson
  Downloading demjson-2.2.4.tar.gz (131 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 131.5/131.5 kB 3.9 MB/s eta 0:00:00
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  Preparing metadata (setup.py) ... error
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Lint returning 0 for erroring geojson

lint.main() isn't returning a non-zero code for a geojson file with errors.

Minimal example:

#!/usr/bin/python
import demjson

lint = demjson.jsonlint()
rc = lint.main(["a.geojson"])
print("rc:", rc)
if rc != 0:
    sys.exit(rc)

a.geojson contains only:

s

Running it (Python 2.7, Windows 7, demjson==2.2.2):

>python test.py
a.geojson:1:0: Error: Unknown identifier: u's'
   |  At line 1, column 0, offset 0 (AT-START)
('rc:', 0)

Expected result: rc should be non-zero and should exit the script.

Problem appears to be _lintcheck() is returning E instead of True or False.

A quick fix is to change the last line of _lintcheck() to:

        if success == True or success == self.SUCCESS_OK:
            return True
        else:
            return False

Which results in:

>python test.py
a.geojson:1:0: Error: Unknown identifier: u's'
   |  At line 1, column 0, offset 0 (AT-START)
('rc:', 1)

Version on CentOS EPEL is out of date and exits 0 on errors

I'm not sure if you're the right person to contact about this, but the version of your software in the CentOS 7 EPEL repository is out of date.

python-demjson                                               noarch                                               2.2.2-1.el7                                                 epel                                               148 k

Installing demjson via pip install demjson gives me version 2.2.4

Using the EPEL provided package, jsonlint only exits with a status of 0 even if the json file in question has errors.

[root@default-centos-7 ~]# jsonlint /etc/sensu/uchiwa.json 
/etc/sensu/uchiwa.json:22:12: Error: Values must be separated by a comma
   |  At line 22, column 12, offset 523
   |  Object started at line 18, column 16, offset 414
/etc/sensu/uchiwa.json:27:12: Error: Values must be separated by a comma
   |  At line 27, column 12, offset 680
   |  Object started at line 23, column 26, offset 567
/etc/sensu/uchiwa.json: has errors
[root@default-centos-7 ~]# echo $?
0

Where as, if I install via pip to get demjson 2.2.4, jsonlint works as intended.

[root@default-centos-7 ~]# jsonlint /etc/sensu/uchiwa.json 
/etc/sensu/uchiwa.json:22:12: Error: Values must be separated by a comma
   |  At line 22, column 12, offset 523
   |  Object started at line 18, column 16, offset 414
/etc/sensu/uchiwa.json:27:12: Error: Values must be separated by a comma
   |  At line 27, column 12, offset 680
   |  Object started at line 23, column 26, offset 567
/etc/sensu/uchiwa.json: has errors
[root@default-centos-7 ~]# echo $?
1

--allow=non-bmp

Hello!

Would it be possible to get a way to allow non-BMP characters? It is currently grouped together with non-portable issues, which is fair, but then I can't allow only non-BMP characters without allowing all the non-portable issues (like empty keys, for instance).

I'm happy to contribute it if you think there would be a chance it would be accepted.

high cpu load

python3.4
from demjson import decode
r = "0e61373903554be6d4f4bd9103364205"
decode(r)

Broken decode() backwards compatibility

Previously, demjson.decode() was documented as having the following signature:

decode(txt, strict=False, encoding=None, **kw)

Now it has the following signature:

decode(txt, encoding=None, **kw)

This breaks code that assumes that strict is the second positional keyword.

Additionally, the resulting error is non-obvious:

>>> demjson.decode('{}', True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/demjson.py", line 5701, in decode
    return_stats=(return_stats or write_stats) )
  File "/usr/local/lib/python2.7/dist-packages/demjson.py", line 4917, in decode
    raise errors[0]
demjson.JSONDecodeError: a Unicode decoding error occurred

jsonlint return value is wrong

It has been reported by @mattboyer (pull request #10 ) and @jannepeltola (pull request #11 ) that the "jsonlint" command line does not always return the expected return value. When feed incorrect JSON it may still return a value of 0 rather than a non-zero error value.

$ echo '{ "abc": [1, 2  }' | jsonlint -v
<stdin>:1:16: Error: Expected a ']' but saw '}'
   |  At line 1, column 16, offset 16
   |  Array started at line 1, column 9, offset 9
<stdin>: has errors

$ echo $?
0

$ jsonlint --version
jsonlint (demjson) version 2.2.2 (2014-06-25)

trailing whitespace

I couldnt see an option for jsonlint to reformat/warn when there is trailing whitespace on each line.

The -F option removes all unnecessary whitespace from a machine readability perspective
I want an option to remove all extraneous whitespace from a human readability perspective.

Does that seem to fit within the scope of jsonlint? If so, I'd be happy to take a crack at it.

'tuple' object has no attribute 'major' (broken in Python 2.6)

Installing demjson v2.0.1 with Python v2.6.8 raises following error, because sys.version_info is returing a tuple and has no attribute 'major'.

-- snip --
Traceback (most recent call last):
File "", line 1, in
File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 1992, in main

File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 1979, in with_ei_usage

File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 1996, in

File "/usr/local/Python-2.6.8/lib/python2.6/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/local/Python-2.6.8/lib/python2.6/distutils/dist.py", line 975, in run_commands
self.run_command(cmd)
File "/usr/local/Python-2.6.8/lib/python2.6/distutils/dist.py", line 995, in run_command
cmd_obj.run()
File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 380, in run

File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 604, in easy_install

File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 653, in install_item

File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 849, in install_eggs

File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 1130, in build_and_install

File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 1115, in run_setup

File "build/bdist.linux-x86_64/egg/setuptools/sandbox.py", line 69, in run_setup
File "build/bdist.linux-x86_64/egg/setuptools/sandbox.py", line 120, in run
File "build/bdist.linux-x86_64/egg/setuptools/sandbox.py", line 71, in
File "setup.py", line 7, in
AttributeError: 'tuple' object has no attribute 'major'
An error occured when trying to install demjson 2.0.1. Look above this message for any errors that were output by easy_install.
-- snap --

Insertion order of (key: value) pairs not preserved with ordered dictionary when using encode_to_file

I've been trying to find a way for demjson to output it's (key, value) pairs in a file in the order they were inserted but that seems rather impossible even when using an OrderedDictionary.

Sample code:

opts.json_packer_builders = (OrderedDict());
opts.json_packer_builders.update({"type": "virtualbox-iso"});
opts.json_packer_builders.update({"guest_os_type": "RedHat_64"});
opts.json_packer_builders.update({"iso_url": opts.image_file_path});
opts.json_packer_builders.update({"iso_checksum": opts.image_hash_value});
opts.json_packer_builders.update({"iso_checksum_type": opts.image_hash_type});
opts.json_packer_root = (OrderedDict());
opts.json_packer_root.update({"builders": ([opts.json_packer_builders])});
demjson.encode_to_file(json_img_template, opts.json_packer_root, 
                                      overwrite = True, compactly = False, indent_amount = 3);

Output:

{  "builders" : [  {  
            "guest_os_type" : "RedHat_64",
            "iso_checksum" : "4ed6c56d365bd3ab12cd88b8a480f4a62e7c66d2",
            "iso_checksum_type" : "sha1",
            "iso_url" : "filepath",
            "type" : "virtualbox-iso"
         } ] }

Expected output:

{  "builders" : [  {  
            "type" : "virtualbox-iso"
            "guest_os_type" : "RedHat_64",
            "iso_url" : "filepath",
            "iso_checksum" : "4ed6c56d365bd3ab12cd88b8a480f4a62e7c66d2",
            "iso_checksum_type" : "sha1",
         } ] }

where

filepath
is a variable user filepath :) ;)

It's not a major issue but is there any way to do that using demjson?

Still alive?

@dmeranda is everything okay? A year ago you talked about pretty a massive update to demjson, but it seems like the project stalled two years ago.

Marketing

You might want to mention why someone would use this for encoding and decoding and not the standard Python package.

demjson pip install fails with python3.7 and 3.7 but not 3.6.

Linux 5.4.0-1037-aws x86_64
Python 3.7.5
python3.7 -m pip install demjson
Collecting demjson
Using cached https://zainar-595572147606.d.codeartifact.us-east-1.amazonaws.com/pypi/dev/simple/demjson/2.2.4/demjson-2.2.4.tar.gz
Complete output from command python setup.py egg_info:
error in demjson setup command: use_2to3 is invalid.

python3.6 -m pip install demjson
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://aws:****@zainar-595572147606.d.codeartifact.us-east-1.amazonaws.com/pypi/dev/simple/
Requirement already satisfied: demjson in /home/emilio/.local/lib/python3.6/site-packages (2.2.4)

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /home/emilio/tmp/pip-build-7zn14mkv/demjson/

This issue, #29, was closed but did not indicate any resolution.

jsonlint changes foat values

I'm seeing the following unexpected behaviour:

I have a datastructure which contains floats, like

"settings":{"max":108.9}

After running jsonlint -s this gets changed to

"settings" : { "max" : 108.90000000000001 }

which is a different value and causes a subsequent run of jsonlint to report the warning:
Warning: Floats larger or more precise than an IEEE "double" may not be portable

The parameter --keep-format doesn't influence this behaviour.

I would expect the linter not to change the value of floats and generate output which would not contain warnings when run through the linter again.

syntax error

Hi!

I tried to import demjson and I got this error. It is working fine with python3.7.

`Python 3.8.6 (default, Oct 11 2020, 14:34:16)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import demjson
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.8/dist-packages/demjson.py", line 645
class json_int( (1L).class ): # Have to specify base this way to satisfy 2to3
^
SyntaxError: invalid syntax

`

OS: Debian Buster on arm with backport python3.8 package.

Please advise.

Thanks,
Warter

Object literal (dictionary) is not terminated

This is my code...
with open('data/pubdata.json', 'r', encoding='utf-8') as f:
print(type(f))
for line in f:
que = demjson.decode(line)
print(que)
And this issue happened: demjson.JSONDecodeError: Object literal (dictionary) is not terminated

Option to mandate unique key names in objects

RFC 4627 (Section 2.2. Objects) allows duplicate key names in objects, but this is not the case for many of the applications. So let's add an option to make key name uniqueness mandatory.

I'm going to work on this. Just let me know if you have a good short option name for this. I'm thinking of "uniq-keys" right now.

Failed to import under Python 2.7.13

Version: 2.2.2-1.el7, 2.2.4-7.fc27
OS: RedHat 7.2
Python version: 2.7.13
The package was installed as a rpm package from :

  1. 2.2.2-1.el7 - from EPEL 7
  2. 2.2.4 - from Fedora official repo

All Failed to execute: import demjson in a python prompt.
ImportError: No module named demjson

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.