Coder Social home page Coder Social logo

randomnessexistance / json-formatter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from callumlocke/json-formatter

0.0 0.0 0.0 197 KB

Makes JSON easy to read.

Home Page: https://chrome.google.com/webstore/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa?hl=en

TypeScript 77.81% CSS 17.28% HTML 4.92%

json-formatter's Introduction

JSON Formatter - the original

Chrome extension that auto-formats JSON when you view it in a browser tab.

Features

  • Fast, even on very long JSON pages
  • Dark mode
  • Syntax highlighting
  • Collapsible trees, with indent guides
  • Clickable URLs
  • Negligible performance impact on non-JSON pages (less than 1 millisecond)
  • Works on any valid JSON page – URL doesn't matter
  • Buttons for toggling between raw and parsed JSON
  • Parsed JSON is exported as a global variable, json, so you can inspect it in the console*

*Typing json the in console is not working since Manifest v3. If you need a workaround, paste this snippet into the console:

json = JSON.parse(document.getElementById("jsonFormatterRaw").querySelector("pre").innerText)

Some JSON documents for testing it on: https://callumlocke.github.io/json-formatter/

Installation

Option 1 (recommended) – Install it from the Chrome Web Store.

Option 2 – Install it from source (see below).

Development

Requirements: Deno (and Node for now).

Initial setup:

  • Clone repo
  • Run pnpm i to get TypeScript typings for chrome (or use npm i if you prefer)
  • Optional: if using VSCode and you need to mess with the Deno build scripts, install the official Deno plugin and set "deno.enablePaths": ["tasks"].

To build it:

  • Run deno task build

To build and rebuild whenever files change:

  • Run deno task dev

To install your local build to Chrome

  • Open Chrome and go to chrome://extensions
  • Enable "Developer mode",
  • Click "Load unpacked",
  • Select the dist folder you built above.

FAQ

Why are large numbers not displayed accurately?

This is a limitation of JavaScript and therefore a limitation of JSON as interpreted by your web browser.

  • Anything above Number.MAX_SAFE_INTEGER (2^53 - 1 or 9007199254740991) is adjusted down to that number.
  • Anything below Number.MIN_SAFE_INTEGER (-2^53 + 1 or -9007199254740991) is adjusted up to that number.
  • Extremely precise floating point numbers are rounded to 16 digits.

It's not JSON Formatter doing this, it's the native JSON.parse in V8. JSON Formatter shows you the parsed values, exactly the same as what you'll see after loading the JSON in JavaScript.

If your API endpoint really needs to represent numbers outside JavaScript's safe range, it should quote them as strings.

Why are object keys sometimes in the wrong order?

What you see in JSON Formatter is a representation of the parsed object/array. It's the same order you'll get with Object.keys( JSON.parse(json) ) in JavaScript.

Historically, the JavaScript standard explicitly stated that object keys can be iterated in any order, and V8 took advantage of this by moving numeric string keys (like "1" or "99999") to the top to facilitate a small performance optimisation. This V8 implementation detail has since become standardised.

But I just want to see exactly what the server spits out

For now, your best option is to just use the "Raw" button to see the raw JSON. This is what the server sent. The "Parsed" buttons represents what you'll get from JSON.parse.

In future JSON Formatter might switch from using JSON.parse to a custom parser (if performance allows) in order to detect when a value has been 'changed' by parsing and show an appropriate warning.

json-formatter's People

Contributors

bitdeli-chef avatar bjhomer avatar bmamlin avatar bricker avatar callumlocke avatar johan avatar markmarkoh avatar pavelgordon avatar tweidman-ispot avatar yannickoo avatar

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.