Skip to content
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

Add support for nested JSON syntax #1169

Merged

Conversation

BoboTiG
Copy link
Contributor

@BoboTiG BoboTiG commented Oct 1, 2021

Proposal

Data fields (key=value) and raw JSON fields (key:=value) now parse the key as JSON form.

Example:

$ http PUT pie.dev/put \
    'object=scalar' \                           # Object — blank key
    'object[0]=array 1' \                       # Object — "0" key
    'object[key]=key key' \                     # Object — "key" key
    'array:=1' \                                # Array — first item
    'array:=2' \                                # Array — second item
    'array[]:=3' \                              # Array — append (third item)
    'wow[such][deep][3][much][power][!]=Amaze'  # Nested object
{
    "array": [
        1,
        2,
        3
    ],
    "object": {
        "": "scalar",
        "0": "array 1",
        "key": "key key"
    },
    "wow": {
        "such": {
            "deep": [
                null,
                null,
                null,
                {
                    "much": {
                        "power": {
                            "!": "Amaze"
                        }
                    }
                }
            ]
        }
    }
}

The new syntax is compatible with other JSON-specific syntax and can be mixed altogether.


Note: it is not doable to simply use the jarg module as it would install PyYAML, and we want to keep our requirements light. I also checked other modules like html-json-forms but I prefer to ship our own code for the same reason: no new module to package. At the end, the new code is maintainable enough, and quite small.

@BoboTiG BoboTiG requested a review from jkbrzt October 1, 2021 13:30
@BoboTiG BoboTiG changed the title Added key$=value for nested JSON syntax into request data Added field$=json for nested JSON syntax support into request data Oct 1, 2021
@BoboTiG BoboTiG marked this pull request as draft October 1, 2021 13:49
@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2021

Codecov Report

❗ No coverage uploaded for pull request base (feature/nested-json@0fc6331). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@                  Coverage Diff                   @@
##             feature/nested-json    #1169   +/-   ##
======================================================
  Coverage                       ?   96.72%           
======================================================
  Files                          ?       73           
  Lines                          ?     4769           
  Branches                       ?        0           
======================================================
  Hits                           ?     4613           
  Misses                         ?      156           
  Partials                       ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0fc6331...51f1ce5. Read the comment docs.

@BoboTiG BoboTiG removed the request for review from jkbrzt October 1, 2021 14:02
@BoboTiG BoboTiG marked this pull request as ready for review October 1, 2021 14:58
@BoboTiG BoboTiG requested a review from jkbrzt October 1, 2021 15:01
@jkbrzt jkbrzt changed the title Added field$=json for nested JSON syntax support into request data Add support for nested JSON syntax Oct 8, 2021
@BoboTiG BoboTiG marked this pull request as draft October 19, 2021 08:14
@BoboTiG BoboTiG force-pushed the mickael/oss-72-syntax-for-nested-json branch 4 times, most recently from 9868e5d to 066973a Compare October 22, 2021 08:26
@BoboTiG BoboTiG marked this pull request as ready for review October 25, 2021 13:11
@isidentical isidentical changed the base branch from master to feature/nested-json November 26, 2021 13:21
@isidentical isidentical force-pushed the mickael/oss-72-syntax-for-nested-json branch from 812f685 to 51f1ce5 Compare November 26, 2021 13:26
@isidentical
Copy link
Contributor

Merging this to feature/nested-json.

@isidentical isidentical merged commit 2bd246c into feature/nested-json Nov 26, 2021
@isidentical isidentical deleted the mickael/oss-72-syntax-for-nested-json branch November 26, 2021 13:44
isidentical added a commit to isidentical/httpie that referenced this pull request Dec 2, 2021
Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
Co-authored-by: Jakub Roztocil <jakub@roztocil.co>
jkbrzt added a commit that referenced this pull request Dec 3, 2021
* Add support for nested JSON syntax (#1169)

Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
Co-authored-by: Jakub Roztocil <jakub@roztocil.co>

* minor improvements

* unpack top level lists

* Write more docs

* doc style changes

* fix double quotes

Co-authored-by: Mickaël Schoentgen <contact@tiger-222.fr>
Co-authored-by: Jakub Roztocil <jakub@roztocil.co>
@isidentical isidentical added this to the HTTPie 3.0 milestone Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Syntax for nested JSON
4 participants