Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json - npm Package Versions

2

11.0.0

Diff

Changelog

Source

11.0.0

  • Backward incompatible and security-related change to parsing the -d DELIM option. (#148)

    The -d DELIM option allows specifying the field delimiter in output:

      % echo '{"name":"trent","age":38}' | json -a name age
      trent 38
      % echo '{"name":"trent","age":38}' | json -a name age -d,
      trent,38
    

    The given "DELIM" string is parsed to allow escapes. For example:

      % echo '{"name":"trent","age":38}' | json -a name age -d'\t'
      trent	38
      % echo '{"name":"trent","age":38}' | json -a name age -d'\n'
      trent
      38
    

    Before this change, that parsing used eval(), which allowed for unintended code execution if an untrusted argument to -d was provided. The fix for this vulnerability changes to use JSON.parse() to support escapes. However that results in a backward incompatible change, because the set of JSON escapes is a subset of JavaScript escapes.

    The only escape I expect that would affect any current user would be the null byte escape (\0) which can be useful for processing values that may have spaces or other likely delimiter characters. For example:

      # BEFORE
      % echo '{"title":"Monsters, Inc.","year":"2001"}' \
        | json -a title year -d'\0' \
        | xargs -0 node -e 'console.log(process.argv)'
      [ 'node', 'Monsters, Inc.', '2001\n' ]
    
      # AFTER
      % echo '{"title":"Monsters, Inc.","year":"2001"}' | json -a title year -d'\0'
      json: error: Unexpected number in JSON at position 2
    

    One must now use the JSON unicode escape syntax, '\u0000':

      % echo '{"title":"Monsters, Inc.","year":"2001"}' \
        | json -a title year -d'\u0000' \
        | xargs -0 node -e 'console.log(process.argv)'
      [ 'node', 'Monsters, Inc.', '2001\n' ]
    
trentm
published 10.0.0 •

Changelog

Source

10.0.0

  • Backward incompatible and security-related change to parsing "lookup" strings.

    This version restricts the supported syntax for bracketed "lookup" strings to fix a possible vulnerability (CVE-2020-7712). With a carefully crafted lookup string, command injection was possible. See #144 for a repro. If you use json (the CLI or as a node.js module) and run arbitrary user-provided strings as a "lookup", then you should upgrade.

    For the json CLI, a "lookup" string is the 'foo' in:

      echo ...some json... | json foo
    

    which allows you to lookup fields on the given JSON, e.g.:

      $ echo '{"foo": {"bar": "baz"}}' | json foo.bar
      baz
    

    If one of the lookup fields isn't a valid JS identifier, then the JS array notation is supported:

      $ echo '{"https://example.com": "my-value"}' | json '["https://example.com"]'
      my-value
    

    Before this change, json would effectively exec the string between the brackets as JS code such that things like the following were possible:

      $ echo '{"foo3": "bar"}' | json '["foo" + 3]'
      bar
    

    This change limits supported bracket syntax in lookups to a simple quoted string:

      ["..."]
      ['...']
      [`...`]      # no variable interpolation
    

    Otherwise generating an error of the form:

      json: error: invalid bracketed lookup string: "[\"foo\" + 3]" (must be of the form ['...'], ["..."], or [`...`])
    
trentm
published 9.0.6 •

Changelog

Source

9.0.6

  • [issue #107] Fix man page installation with npm install -g json.
trentm
published 9.0.5 •

Changelog

Source

9.0.5

  • [issue #112] Improve streaming (json -ga) performance for very long lines. For example, using a 35 MB JSON object on one line gave a 50x speed improvement. However, this is restricted to streaming of newline-separated JSON as opposed to adjacent JSON objects not separated by newlines ({"a":1}{"a":2}). The former case is expected to be much more common, and the latter may take a slight performance hit from this change.
trentm
published 9.0.4 •

Changelog

Source

9.0.4

  • [issue #108] Fix a crash on json foo.bar if "foo" is null.
trentm
published 9.0.3 •

Changelog

Source

9.0.3

  • [issue #82] Fix a race in -I/--in-place temp file creation. By https://github.com/inator
trentm
published 9.0.2 •

Changelog

Source

9.0.2

  • [pull #72] Correct examples in docs for conditional filtering.
trentm
published 9.0.1 •

Changelog

Source

9.0.1

  • [issue #71] Support -o json-tab and -o jsony-tab for TAB (i.e. \t) indentation of emitted JSON.
trentm
published 9.0.0 •

Changelog

Source

9.0.0

  • [issue #52] Fix termination on EPIPE in some cases.

  • Add -0, -2, -4 options to more conveniently set the JSON indentation without changing the mode.

  • [pull #64] Add -M, --items option for "itemizing" key/value pairs in an object for easy iteration. For example:

      $ echo '{"trent":{"age":38},
               "ewan": {"age":4}}' | json -M
      [
        {
          "key": "trent",
          "value": {
            "age": 38
          }
        },
        {
          "key": "ewan",
          "value": {
            "age": 4
          }
        }
      ]
    
      $ echo '{"trent":{"age":38},
               "ewan": {"age":4}}' | json -Ma key value.age
      trent 38
      ewan 4
    
      # List people that can vote.
      $ echo '{"trent":{"age":38},
               "ewan": {"age":4}}' | json -M -c 'this.value.age > 18' -a key
      trent
    

    Thanks to AndrewO for providing this!

  • Backward incompatible change to -c CODE and -e CODE changing their implementation to use a JS function for processing rather than vm.runInNewContext. This is the technique for which the -C CODE and -E CODE options were added in version 7.0.0. Basically: This technique is obviously better because it is 10x faster, so it is being made the only supported way. -C and -E, then, become synonyms and may be removed in a later release.

    Unfortunately this does mean a few semantic differences in the CODE, the most noticeable of which is that this is required to access the object fields:

      # Bad. Works with json < v9...
      $ echo '{"green": "eggs"}' | json-v8 -e 'green="ham"'
      {
        "green": "ham"
      }
    
      # ... does *not* work with json v9.
      $ echo '{"green": "eggs"}' | json -e 'green="ham"'
      {
        "green": "eggs"
      }
    
      # Good. Works with all versions of json.
      $ echo '{"green": "eggs"}' | json -e 'this.green="ham"'
      {
        "green": "ham"
      }
    

    The old behaviour of -c and -e can be restored with the JSON_EXEC=vm environment variable:

      $ echo '{"green": "eggs"}' | JSON_EXEC=vm json -e 'green="ham"'
      {
        "green": "ham"
      }
    

    See the notes on json 7.0.0 below for full details on the performance improvements and semantic changes.

trentm
published 8.0.0 •

Changelog

Source

8.0.0

  • [pull #70] Move from 'jsontool' to 'json' in the npm registry! Thanks to https://github.com/zpoley for graciously giving up the name, and to @izs for driving. npm install json FTW. Here after jsontool will stagnate at version 7.0.2.
2
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc