Giter Site home page Giter Site logo

virtual-json-viewer's Introduction

mentioned in awesome jq donate

logo Virtual Json Viewer

Browser plugin that uses virtual DOM to render JSONs with built-in search, JQ filtering and many other features.

preview

Browser Store

chrome firefox

Manifest Version

The default build for Chrome relies on the new Manifest V3 and requires Chromium version 106 or higher.
If you are running an older version of Chromium because reasons... I got your back! Simpy follow the instructions on how to perform a manual installation using a MV2 release.

Why?

"Oh my! There are plenty of json viewers, why making a new one?"

Rightful question, and the answer is quite simple: the others weren't good enough [for my needs].

I often have to debug large json payloads, so large that every other plugin for chrome I tried freezed without showing any content.

"Good for you, but my payloads are small, pretty and strawberry flavoured"

That's ok, if you are happy with your current plugin, no need to change.

And if you want to come back later don't worry, we'll still be here, with blazing fast loading time, built-in search, JQ filtering and many other features... but no strawberries, sorry

Features

  • JSON rendering using virtual DOM and collapsible nodes
    • Color-encoded value types
    • Collapse/expand all nodes
    • Preview nested item count for closed nodes
    • Clickable URLs
    • Option to sort JSON keys alphabetically
  • Full text search
    • Highlight search results
    • Option to completely hide subtrees without any search match
    • Option to enable case sensitive search
  • JQ filtering
  • Raw JSON viewer
    • Prettify/minify
  • Download JSON
  • Keyboard shortcuts
  • Appearance
    • Light/dark mode
    • Custom theme
    • Internationalization

Keyboard shortcuts

🍏 On MacOS Ctrl is replaced by the command key (⌘)

Navigate UI
Action Primary Secondary
Focus Next element Tab
Focus Previous element Shift + Tab
Trigger button Enter
Focus Search Ctrl + f /
Focus JQ Ctrl + Shift + f
Focus Viewer Ctrl + 0
Toolbar
Action Primary Secondary
Toggle Tree/Raw viewer Ctrl + i
Expand Ctrl + e
Collapse Ctrl + Shift + e
Save Ctrl + s
Tree viewer
Action Primary Secondary
Start navigation Enter
End navigation Escape
Go to next ArrowDown j
Go to previous ArrowUp k
Go to next page PageDown Shift + j
Go to previous page PageUp Shift + k
Go to first Home gg
Go to last End Shift + g
Open node ArrowRight l
Close node ArrowLeft h
Toggle node open/close Spacebar
Select key text Shift + ArrowLeft Shift + h
Select value text Shift + ArrowRight Shift + l
Select node text Ctrl + a
Raw viewer
Action Primary Secondary
Select all text Ctrl + a
Deselect text Escape

FAQ

Why the extension doesn't work when opening a file from filesystem?

On Chrome

  1. go to chrome://extensions/
  2. select "Virtual Json Viewer"
  3. enable the toggle "Allow access to file URLs"

If this doesn't solve the issue make sure you are using the latest version of both Chrome and Virtual Json Viewer, or manually install the correct build for your version.

Why JQ is not available?

JQ has been compiled to WebAssembly and included in this plugin, but some website's Content Security Policy doesn't allow WASM execution. In those cases the JQ command bar is not shown.

Example: https://api.github.com/users/paolosimone/repos

See also Issue #15

Why this valid JQ command doesn't work?

JQ commands in Virtual Json Viewer must return valid json, otherwise the parsing of the result will fail with an error e.g.

Unexpected token { in JSON at position 337

Why? The core feature of Virtual Json Viewer is the navigation of (possibly large) json thanks to virtual DOM that allows on-demand rendering. JQ filtering has been added on top of that, just as handy utilities to further improve the user experience.

Example

Let's say we want to extract all the page titles from this Wikipedia search.

.query.search[].title will fail because a sequence of strings is not a valid json:

"Pizza"
"Hawaiian pizza 😱"
"History of pizza"
"Pizza Margherita"
...

We should use [.query.search[].title] instead to obtain a json array:

[
  "Pizza",
  "Hawaiian pizza 😱",
  "History of pizza",
  "Pizza Margherita",
  ...
]

ok ok, I added the scream emoji

Why the content shown by the extension is different from the actual JSON?

The json content is parsed using Javascript's JSON.parse in order to be rendered both in Tree and Raw view, and even from Download button. For the vast majority of cases this shouldn't be a problem but if you find yourself in need of debugging the original json text I'd suggest you to start praying turn to more suitable tools like API clients and text editors.

Here are some well-known Javascript behaviour that could lead to differences between the original json and its javascript parsed object.

Large numbers are truncated

Integers outside the range Number.MIN_SAFE_INTEGER and Number.MAX_SAFE_INTEGER are rounded (MDN)

JSON.parse('{"wrong": 10000000000000099}')
{wrong: 10000000000000100}

Floating point numbers are rounded to 16 digits

JSON.parse('{"wrong": 1.12345678901234567890}')
{wrong: 1.1234567890123457}

Keys order is not preserved

Even disabling the alphabetical ordering feature flag there is no guarantee that the order of keys on screen will be the same as the original json. The actual order will be the output of Object.keys(JSON.parse(json)). For instance by ECMAScript specification integer-like keys will be iterated first (MDN)

Object.keys(JSON.parse('{"ZZZ": "_", "AAA": "_", "42": "_"}'))
['42', 'ZZZ', 'AAA']

Unicode escapes are parsed

JSON.parse('{"\u3053\u3093\u306B\u3061\u306F": "\u4E16\u754C"}')
{'こんにけは': 'δΈ–η•Œ'}

Manual Installation

Get the build

I'm confused, which manifest version should I get?

Browser Manifest
Chrome 106+ V3
Chrome (older) V2
Firefox V2

Note: the only differences are in the manifest. The underlying extension code is the same for all builds

From Release

Download the latest build from the release page and extract the content

  • virtual-json-viewer-{version}: Chrome manifest V3
  • virtual-json-viewer-{version}-mv2: Chrome manifest V2
  • virtual-json-viewer-{version}-firefox: Firefox (manifest V2)

From source

cd extension
yarn install

yarn build          # Chrome  - Manifest V3
yarn build-mv2      # Chrome  - Manifest V2
yarn build-firefox  # Firefox - Manifest V2

Install the extension

Chrome

  1. Open the Extension Management page by navigating to chrome://extensions
  2. Enable Developer Mode by clicking the toggle switch next to Developer mode
  3. Click the load unpacked button and select the build directory

Firefox

Disable native json viewer

  1. Go to about:config
  2. Search for devtools.jsonview.enabled
  3. Set to false

Load extension

  1. Go to about:debugging
  2. Click "This Firefox"
  3. Click "Load Temporary Add-on" and select the build directory

Note: The extension is automatically removed when Firefox is closed and must be manually loaded on next start.

Others

The extension has not been tested on other browsers, but should work on any chromium browser.

Contributing

Bug fix

Ooops! Just open an issue with detailed description of what happened and how to reproduce it... Or go for it and open a PR with the patch if you are brave enough!

Feature request

In general I'd rather keep the feature set of Virtual Json Viewer small and well defined, but if you have a proposal feel free to open an issue and we will discuss it.

Translation

New languages are welcome, open a PR and follow these steps.

Translation files are in json format (yo dawg!) and are located in the translation folder extension/src/viewer/localization/translations.

To add a new language:

  1. Make a copy of the en.json translation file and rename it with the ISO 639-1 two-letter code of the new language (e.g. es.json for Spanish)
  2. Translate all the values in the new translation file
  3. Register the new language by adding it to the enum (and other structures) inside extension/src/viewer/localization/Localization.ts

Donation

❌ I won't accept money in exchange for change/feature requests.

🍺 If you still want to share a beer as appreciation for my work, go ahead and smash the donate button!

donate

Local development

Run yarn start to serve the extension as a web app with hot reload.

Always yarn format before creating a commit.

Performance

Disclaimer: this is NOT a formal benchmark, just a few tests with syntethic data to give an idea of loading performance time.

Setup

  • Virtual Json Viewer v1.0.0
  • Macbook Pro 16 (2019) 2,6 GHz 16 GB
  • Chrome 106.0.5249.119
  • Jsons are randomly generated using this script (fixed dept: 10)
  • Files are loaded from disk
  • Load time recorded with Chrome DevTool
    1. Open file in chrome
    2. From "Performance insights" tab click "Measure page load"
    3. Take the "Largest Contentful Paint" (LCP)

Results

Siblings per level File Size Load time
110 ~100 KB ~300 ms
1100 ~1 MB ~350 ms
11000 ~10 MB ~900 ms
110000 ~100 MB ~8000 ms

References

Tool Usage
anchorme Convert URLs to clickable HTML links
cra-template-complex-browserext-typescript Project scaffolding, huge help!
customize-cra Break webpack config, then fix it
jq-wasm JQ in the browser
json-stable-stringify Sort keys on JSON serialization apparently is rocket science
React Learn how to write a frontend application without jQuery and bootstrap
react-color Easily edit the custom theme and, more importantly, looking professional while doing it
react-vtree Render the JSON. I'd say it's a pretty important role
TailwindCSS Prevent me from touching CSS files
Typescript Try to forget I'm actually writing JS 🀒
uid Fast generation of unique keys for React lists
vscode-icons Keep UI buttons clean and intuitive

License

MIT License. See also LICENSE file.

virtual-json-viewer's People

Contributors

paolosimone 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

Watchers

 avatar  avatar

virtual-json-viewer's Issues

Suggestion: detect when dark mode changes on the desktop

Hi Paolo,

I discovered this project in your response to my comment about JSON viewers yesterday, great job with this extension!

I've been using it for a little while today and noticed that while you already detect when the theme is changed in the options, the same doesn't happen when the system itself (the desktop really) switches modes. So changing the mode in the options applies the chosen theme immediately, but if you have "system" selected and the desktop itself switches, the theme doesn't change until the tab is reloaded.

Steps to reproduce:

  1. Start with the OS desktop in "light mode"
  2. In the options, select theme: "System theme"
  3. Open a JSON file, it's light-themed as expected
  4. Switch the desktop to "dark mode"
  5. The JSON render only becomes dark if the tab is reloaded (this happens from dark to light as well, of course)

It seems like just adding a watcher function with setInterval to detect this would likely be enough, although I can't say I'm qualified enough to make recommendations on Chrome extensions :-)

This is clearly a pretty minor issue, but I figured that since you had already gone through the effort of applying the theme immediately using a storage event listener when the options are changed, you might want to have each page do the same when the desktop switches modes too.

Enable the plugin on json content, regardless of content type

Request from @RVFET (original comment here)

Would be great if the extension could fallback to trying to parse the response into json even when content type does not match any json format, just as a last chance, it'd be a great addition. I'm aware that it'd create some performance bottlenecks since it'd need to check every page you visit but it could be an option that we can toggle, or perhaps manual wildcard/regex based custom website matching could help a ton, too.

Feature Request: Mouseless work by keyboard shortcuts

Could you please define default keyboard shortcuts at least for

  1. Expand All
  2. Collapse All
  3. Navigate To Next Array Element
  4. Navigate To Previous Array Element
  5. Expand/Collapse Current Element
  6. Jump To JQ Filter TextBox
  7. Scroll Up
  8. Scroll Down
  9. Switch To Raw View
  10. Switch To Tree View
  11. Case Sensitive On/Off
  12. Hide/Unhide mismatch

MacOS keyboard hotkeys for text selection doesn't work in plugin's Tree mode

Hi,
Could you please make it possible to use MacOS keyboard hotkeys for text selection, such as:

Select text to beginning of a line – Shift+Command+Left Arrow
Select text to end of a line – Shift+Command+Right Arrow
Select text to beginning of current word – Shift+Option+Right Arrow
Select text to end of current word – Shift+Option+Right Arrow
Select text to beginning of all text – Shift+Command+Up Arrow
Select text to end of all text – Shift+Command+Down Arrow

( or introduce some new hotkeys for text selection, for example like https://www.jetbrains.com/go/guide/tips/expanding-shrinking-selection/ ) in virtual-json-viewer plugin's in Tree mode?

Because it's currently hard to copy text in that mode, for example UUIDs

Unexpected non-whitespace character after JSON at position 7509

I get a "Unexpected non-whitespace character after JSON at position 7509" when trying to use jq filtering. If I use jq from the cmd line the filtering works fine.

Is there a way to get more debug info about the JSON in question?

The JSON does contain UTF like "GΓ–TEBORG" and "HΓΈjrup"

[BUG] Huge errors cover the search bar

Buggy behavior

When an error is too big it (sometimes) ends up hiding the full search bar. (see attached screenshot)

Expected behavior

It doesn't happen (they are output below the bar).

Screenshot

1669283063

Workaround

Reload the window.

JQ is disabled on strict CSP

Description

When I load a json from a remote host served with strict Content Security Policy (CSP) rules, the JQ filter bar is not showing.
Example: https://api.github.com/users/paolosimone/repos

Details

This happens because JQ filtering relies on WebAssembly, but WASM execution is enabled only if CSP allows the execution of unsafe code ('script-src': 'unsafe-eval')... even if the wasm file is the one bundled with the extension package!

Error: Wasm code generation disallowed by embedder

References:

Why not Sandbox?

The recommended approach is to run wasm code in a sandbox and send/receive data through message passing. This solution introduces an additional overhead due to serialization/deserialization of the message content (in our case, the JSON itself).

How much overhead? Will it continue to work smoothly with ~10MB json?

Don't know, I guess we could give it a try (at least as a fallback strategy) before jumping to conclusion.

But I want to use the interactive JQ feature now

I feel you. In the meantime you could download the json (floppy disk icon) and load the file in the browser.

jq doesn't work

 curl https://wttr.in/Detroit\?format\=j1 | jq '.weather|.[].date'                                  [2022-05-19 23:58:52]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 48898  100 48898    0     0   112k      0 --:--:-- --:--:-- --:--:--  115k
"2022-05-19"
"2022-05-20"
"2022-05-21"

works as expected but Virtual Json Viewer plugin throws Unexpected string in JSON at position 13 error for the same expression:
.weather|.[].date

See also https://jqplay.org/s/DHmRZozMOj9
Could you please fix it and make my life easier?

Set default application state in settings

It would be nice to set some default application state in extensions settings so that they are applied when opening a new page, e.g. viewer mode (tree/raw) or search visibility (all/subtree/matches).

This is quite a challenge because extensions settings are loaded in async and are not available on first render when the application state is set in session storage. Need to convince React that it can be done.

Feature Request: Expose default expanded/collapsed in settings

Great experience with the extension so far, coming from plain JSONVue.

I'd love to be able to set expanded/collapsed as a default in settings.

Usually I like to get an overview real quick and this would save me a click or ctrl+e a bunch of times.

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.