8000 gh-122873: Allow "python3 -m json" to work by treyhunner · Pull Request #122884 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-122873: Allow "python3 -m json" to work #122884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
27e449d
Rename json.tool to json.__main__
treyhunner Aug 1, 2024
423c971
Make json.tool delegate to json.__main__
treyhunner Aug 1, 2024
1c1a8fa
Note json.tool deprecation
treyhunner Aug 1, 2024
f8f6931
Move main function from json.__main__ to json.tool
treyhunner Aug 2, 2024
834fbd7
Remove deprecation warning
treyhunner Aug 9, 2024
62afcf1
Fix module name as shown at command-line
treyhunner Aug 10, 2024
f58e60a
Update docs and what's new for json.tool to json
treyhunner Aug 10, 2024
168082a
Remove duplicate json module description from docs
treyhunner Aug 10, 2024
52039ee
Give up on marking `-m` as an option
treyhunner Aug 10, 2024
2e37475
Remove unnecessary newline in changed note
treyhunner Aug 10, 2024
efd0503
Remove now-invalid json.tool module reference
treyhunner Aug 10, 2024
c6bb211
Add news entry with blurb
treyhunner Aug 10, 2024
e768e39
Remove older raw string usage in docstring
treyhunner Aug 10, 2024
a6b5c0d
Use sentence case in section title
treyhunner Aug 10, 2024
8000 3105bc2
Add CLI invocation for easier copy-pasting
treyhunner Aug 10, 2024
238fc57
Update json.__init__ docstring for python -m json
treyhunner Aug 10, 2024
7f704bf
Note `python -m json` in What's New
treyhunner Aug 10, 2024
fba68ac
Use SystemExit consistently in json package
treyhunner Aug 10, 2024
8662c81
Improve grammar in news
treyhunner Aug 12, 2024
52129e6
Add json.tool submodule documentation reference back in.
treyhunner Aug 12, 2024
016206d
Note that json.tool still works for compatibility reasons
treyhunner Aug 12, 2024
9b22285
Note that json.tool implements the CLI
treyhunner Aug 12, 2024
9fd0c1c
Reference json.__main__ in json.tool docstring
treyhunner Aug 12, 2024
734fbf9
Switch json.tool to json on listing of Python CLIs
treyhunner Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update docs and what's new for json.tool to json
  • Loading branch information
treyhunner committed Aug 10, 2024
commit f58e60ae5a8599d6c9a14046f1ce37223e7d114d
31 changes: 19 additions & 12 deletions Doc/library/json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ Extending :class:`JSONEncoder`::
['[2.0', ', 1.0', ']']


Using :mod:`json.tool` from the shell to validate and pretty-print:
Using :mod:`json` from the shell to validate and pretty-print:

.. code-block:: shell-session

$ echo '{"json":"obj"}' | python -m json.tool
$ echo '{"json":"obj"}' | python -m json
{
"json": "obj"
}
$ echo '{1.2:3.4}' | python -m json.tool
$ echo '{1.2:3.4}' | python -m json
Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

See :ref:`json-commandline` for detailed documentation.
Expand Down Expand Up @@ -678,40 +678,47 @@ when serializing instances of "exotic" numerical types such as


.. _json-commandline:
.. program:: json.tool
.. program:: json

Command Line Interface
Command-Line Interface
----------------------

.. module:: json.tool
.. module:: json
:synopsis: A command line to validate and pretty-print JSON.

**Source code:** :source:`Lib/json/tool.py`

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

The :mod:`json.tool` module provides a simple command line interface to validate
and pretty-print JSON objects.
The :mod:`json` module can be invoked as a script,
using the interpreter's :option:`-m` switch,
to validate and pretty-print JSON objects.

If the optional ``infile`` and ``outfile`` arguments are not
specified, :data:`sys.stdin` and :data:`sys.stdout` will be used respectively:

.. code-block:: shell-session

$ echo '{"json": "obj"}' | python -m json.tool
$ echo '{"json": "obj"}' | python -m json
{
"json": "obj"
}
$ echo '{1.2:3.4}' | python -m json.tool
$ echo '{1.2:3.4}' | python -m json
Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

.. versionchanged:: 3.5
The output is now in the same order as the input. Use the
:option:`--sort-keys` option to sort the output of dictionaries
alphabetically by key.

.. versionchanged:: 3.14
The :mod:`json` module may now be executed as a script.

Previously :mod:`json.tool` provided the :mod:`json` module's
command-line interface.


Command line options
Command-line options
^^^^^^^^^^^^^^^^^^^^

.. option:: infile
Expand All @@ -720,7 +727,7 @@ Command line options

.. code-block:: shell-session

$ python -m json.tool mp_films.json
$ python -m json mp_films.json
[
{
"title": "And Now for Something Completely Different",
Expand Down
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.14.rst
5429
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ Add notes for JSON serialization errors that allow to identify the source
of the error.
(Contributed by Serhiy Storchaka in :gh:`122163`.)

Enable :mod:`json` module to work as a script using the :option:`-m` switch.
(Contributed by Trey Hunner in :gh:`122873`.)

operator
--------

Expand Down
0