gjson icon indicating copy to clipboard operation
gjson copied to clipboard

Can I add a default value without a key?

Open DMLfor opened this issue 1 year ago • 10 comments

{
    "name": {
        "first": "Tom",
        "last": "Anderson"
    },
    "age": 37,
    "children": [
        "Sara",
        "Alex",
        "Jack"
    ],
    "fav.movie": "Deer Hunter",
    "friends": [
        {
            "first": "Dale",
            "last": "Murphy",
            "age": 44,
            "nets": [
                "ig",
                "fb",
                "tw"
            ],
            "others": [
                {
                    "k": "v",
                    "v": "k"
                },
                {
                    "k": "v",
                    "v": "k"
                }
            ]
        },
        {
            "last": "Craig",
            "age": 68,
            "nets": [
                "fb",
                "tw"
            ],
            "others": [
                {
                    "v": "k"
                },
                {
                    "k": "v",
                    "v": "k"
                }
            ]
        },
        {
            "first": "Jane",
            "last": "Murphy",
            "age": 47,
            "nets": [
                "ig",
                "tw"
            ],
            "others": [
                {
                    "k": "v",
                    "v": "k"
                },
                {
                    "v": "k"
                }
            ]
        }
    ]
}

Current results:

"friends.#.first"    >> ["Dale", "Jane"]
"friends.#.others.#.k"  >> [["v", "v"], ["v"],["v"]]

With default value:

"friends.#.first"    >> ["Dale", nil, "Jane"]
"friends.#.others.#.k"  >> [["v", "v"], [nil, "v"],["v", nil]]

Thanks:)

DMLfor avatar Sep 14 '22 15:09 DMLfor