Giter Site home page Giter Site logo

pyjsonviewer's Introduction

PyJSONViewer

A JSON file data viewer using pure python

CI Downloads Downloads Downloads

Gallery

  • Mac OS

img1

  • Windows10

img1

  • Ubuntu

img1

What is this?

This is a JSON file data viewer based on python.

It only uses built-in libraries of python (tkinter, json).

Features:

  1. Minimum dependency.

  2. Multi-platform (Mac, Windows, Linux).

  3. Easy to use.

Requirements

  • Python 3.7 or higher

Download

$ pip install PyJSONViewer

or download as zip.

How to use

Select JSON file with CUI.

  1. Run pyjsonviewer with -f option and the path to a JSON file:

$ pyjsonviewer -f path_to_json_file/sample.json

  1. JSON data tree will be shown.

Select JSON file with GUI.

  1. Run pyjsonviewer

$ pyjsonviewer

  1. File->Open and then select json file.

  2. JSON data tree will be shown.

You can set initial directory:

$ pyjsonviewer -d path_to_json_file_dir

Select JSON file from history.

  1. Run pyjsonviewer.py

  2. File->"Open from history" and then double click a json file path from the list.

img1

  1. JSON data tree will be shown.

Select JSON file with drag and drop.

  1. Run pyjsonviewer.py with the option -o

$ python pyjsonviewer.py -o path_to_json_file_dir

  1. File browser is shown.

  2. You can drag and drop a JSON file to the file browser.

Menu bar function

  • Expand all items: Tools -> Expand all

  • Collapse all items: Tools -> Collapse all

  • Show version: Help -> About

  • Show github page: Help -> GitHub page

  • Show release note: Help -> Release note

Inside python code

View json file

import pyjsonviewer

pyjsonviewer.view_data(json_file="dat/list.json")

JSON data tree will be shown.

View json object

import pyjsonviewer
json_object = {"a":[1,2,3], "b":"test"}
pyjsonviewer.view_data(json_data=json_object)

JSON data tree will be shown.

Vimrc setting

If you are a vim user, you can set this command in your vimrc.

"JSON format
function! JsonFormat()
	%!python -m json.tool
endfunction
command! JsonFormat :call JsonFormat()

"JSON viewer
function! JsonViewer()
	"%!python -m pyjsonviewer -f % > /dev/null
	let filename = expand('%')
	let s:job = job_start(
	\   ["/bin/sh", "-c", "python -m pyjsonviewer -f".filename],{})
endfunction
command! JsonViewer :call JsonViewer()

When you are editing a json file with vim,

you can open it using PyJSONViewer with

: JSONViewer()

You can also format json file with

: JSONFormat()

Open a link with a browser

If a URL is included in a json file,

you can open it with a browser with double click the URL.

License

MIT

Author

pyjsonviewer's People

Contributors

abshk-jr avatar ankush-chander avatar atsushi-sakai avatar atsushisakai avatar bertdida avatar dskkato 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyjsonviewer's Issues

object has no attribute w

Traceback (most recent call last):
File "pyjsonviewer.py", line 299, in
main()
File "pyjsonviewer.py", line 255, in main
root.tk.call('wm', 'iconphoto', root.tk.w,
AttributeError: '_tkinter.tkapp' object has no attribute 'w'

This issue is fixed for me by changing root.w to root at pyjsonviewer.py:255

VERSION file not found - Cannot install

Hello,
I am installing PyJSONViewer via the following command
pip install --proxy <MYPROXY> PyJSONViewer

The error says that VERSION file is missed: actually it does not seem to be packed up (checked via tar.gz download)

I am on Win10, using PyCharm and a dedicated Python 3.7 environment created with Miniconda3.
This happens both from the command line and from PyCharm, of course.

Thanks!
Andrea

Error log:
`
Collecting PyJSONViewer
Downloading https://files.pythonhosted.org/packages/be/63/deea6ffc40306191fac73abab6e31ccca1ba5f8547c6f5aab71a35bf7cf0/PyJSONViewer-1.4.0.tar.gz (46kB)

ERROR: Command errored out with exit status 1:
 command: 'C:\Users\MYSELF\miniconda3\envs\MYENV\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\MYSELF\\AppData\\Local\\Temp\\pycharm-packaging\\PyJSONViewer\\setup.py'"'"'; __file__='"'"'C:\\Users\\MYSELF\\AppData\\Local\\Temp\\pycharm-packaging\\PyJSONViewer\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
     cwd: C:\Users\MYSELF\AppData\Local\Temp\pycharm-packaging\PyJSONViewer\
Complete output (7 lines):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\MYSELF\AppData\Local\Temp\pycharm-packaging\PyJSONViewer\setup.py", line 18, in <module>
    from pyjsonviewer import pyjsonviewer
  File "C:\Users\MYSELF\AppData\Local\Temp\pycharm-packaging\PyJSONViewer\pyjsonviewer\pyjsonviewer.py", line 20, in <module>
    VERSION = open(os.path.dirname(os.path.abspath(__file__))+"/../VERSION", "r").readline()
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\MYSELF\\AppData\\Local\\Temp\\pycharm-packaging\\PyJSONViewer\\pyjsonviewer/../VERSION'
----------------------------------------

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
`

UTF-8 encoded files not reading; seems to require cp-1252 encoding

Per RFC 8259, §8.1, JSON files are UTF-8 encoded.

However, when I use Japanese characters in my UTF-8 encoded JSON files, the program won't load them.

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python37-32\lib\tkinter\__init__.py", line 1702, in __call__
    return self.func(*args)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyjsonviewer\pyjsonviewer.py", line 118, in select_json_file
    self.set_table_data_from_json(file_path)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyjsonviewer\pyjsonviewer.py", line 187, in set_table_data_from_json
    data = self.load_json_data(file_path)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyjsonviewer\pyjsonviewer.py", line 232, in load_json_data
    return json.load(f)
  File "C:\Program Files (x86)\Python37-32\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Program Files (x86)\Python37-32\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 4251: character maps to <undefined>

This is arguably a problem with the Python decoder, but it can be resolved in source code, with:

raw_bytes = open(path_to_file, "rb").read()
return json.loads(raw_bytes.decode("utf-8"))

I'm having the issue of missing /VERSION file in a vanilla install of Python

I have a fresh install of Python 3.8 x64 on Windows 10

I have run pip install pyjsonviewer and it looked good.

I go to run pyjsonviewer and receive error:

PS C:\PYTHON38-64\Lib\site-packages\pyjsonviewer> py .\pyjsonviewer.py
Traceback (most recent calllast):
File ".\pyjsonviewer.py", line 20, in
VERSION = open(os.path.dirname(os.path.abspath(file))+"/VERSION", "r").readline()
FileNotFoundError: [Errno 2] No such file or directory: 'C:\PYTHON38-64\Lib\site-packages\pyjsonviewer/VERSION'

Cannot open files that do not end with ".json"

I'd like there to be the capacity to read not only ".json" files, but to be able to select also to select from ALL files.

For example, Chrome bookmarks are stored in a file called "Bookmarks" as JSON, but it can't be opened, without copying the file to a temporary directory, and renaming the copy.

v1.4.0

  • fuzzy search for json item

Need support for list data.

Example :

[  
   {
        "date": "2017-01-01",
        "title": "Automated question answering system using ontology and semantic role",
        "doc_id": "258cc0fd7973def42234f3db5ffdfd2a",
    },
    {
        "date": "2011-01-01",
        "title": "A new fuzzy-based method to weigh the related concepts in semantic focused web crawlers",
        "doc_id": "71ae01c53f4eeb7d402f5bcfbce36f9f",
     }
]

release v1.3.0

  • add shortcut for every function
  • add all expand function
  • add all collapse function
  • add release note viewer
  • add app icon

Unable to open JSON file in pwd

Installed using pip3 install pyjsonviewer — Received a _tkinter error and resolved that using brew install python-tk

I have a .json file located in a directory (pwd) — repos/data_objects/exported.json

When I run python3 pyjsonviewer -f exported.json OR python3 pyjsonviewer -f repos/data_objects/exported.json I get the same error.

(14:52:30)──> python3 pyjsonviewer -f exported.json                                               2 ↵ ──(Tue,Oct11)─┘
/opt/homebrew/bin/python3: can't open file '/Users/username/repos/data_objects/pyjsonviewer': [Errno 2] No such file or directory 

AND

(14:51:19)──> python3 pyjsonviewer -f ~/repos/data_objects/exported.json                       2 ↵ ──(Tue,Oct11)─┘
/opt/homebrew/bin/python3: can't open file '/Users/username/repos/data_objects/pyjsonviewer': [Errno 2] No such file or directory

After installing python-tk with brew (brew install python-tk) running $ pyjsonviewer spawns a tree nav pane, as expected.

/opt/homebrew/lib/python3.10/site-packages/pyjsonviewer/pyjsonviewer.py start!!

From the pyjsonviewer pane, I'm able to open the file.

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.