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

[FEAT] Support Set with Slice (Array) Index Using Square Brackets? #96

Open
KiddoV opened this issue Aug 24, 2022 · 7 comments
Open

[FEAT] Support Set with Slice (Array) Index Using Square Brackets? #96

KiddoV opened this issue Aug 24, 2022 · 7 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@KiddoV
Copy link

KiddoV commented Aug 24, 2022

It would be nice to support slice index in .Set()
Example:

config.Set("parent.child[0]", "Test1")
config.Set("parent.child[1]", "Test2")

Currently, the result will be like:

{
    "parent": {
        "child[0]": "Test1",
        "child[1]": "Test1"
    }
}

==> Expecting result would look like:

{
    "parent": {
        "child": [
          "Test1",
          "Test2"
        ]
    }
}

Thanks,

@inhere
Copy link
Member

inhere commented Aug 25, 2022

Has been implemented, the next version will be released.

@KiddoV
Copy link
Author

KiddoV commented Aug 25, 2022

Glad to hear!!!

@inhere
Copy link
Member

inhere commented Aug 28, 2022

hi, new version has been released. https://github.com/gookit/config/releases/tag/v2.1.4

@inhere inhere closed this as completed Aug 28, 2022
@inhere inhere added the enhancement New feature or request label Aug 28, 2022
@KiddoV
Copy link
Author

KiddoV commented Mar 22, 2024

@inhere
Does the new version v2.2.1 also support array of object like:

{
    "parent": [
        {
            "child1Field1": 1,
            "child1Field2": 2
        },
        {
            "child2Field1": 3,
            "child2Field2": 4
        }
    ]
}

When I do config.Set("parent[0].child1Field1", 5) it doesn't work tho.
Result:

{
    "parent": [
        {
            "child1Field1": 1,
            "child1Field2": 2
        },
        {
            "child2Field1": 3,
            "child2Field2": 4
        }
    ],
    "parent[0]": {
        "child1Field1": 5
    }
}

Expecting result:

{
    "parent": [
        {
            "child1Field1": 5,
            "child1Field2": 2
        },
        {
            "child2Field1": 3,
            "child2Field2": 4
        }
    ]
}

Can you also implement to support this?
Thanks!

@KiddoV
Copy link
Author

KiddoV commented Mar 22, 2024

This must be a bug or something. I noticed we can do this, but only the second time on. (ONLY when the JSON file doesn't contain these config yet)
When call config.Set("parent[0].child1Field1", 5) the first time, data will be created like this:

{
    [...]
    "parent[0]": {
        "child1Field1": 5
    }
}

But call the second time it would be correct:

{
    [...]
    "parent": { //When calling the second time and so on...
        [...]
        {
            "child1Field1": 5,
            [...]
        }
    },
    "parent[0]": { //When calling the first time
        "child1Field1": 5
    }
}

And when I reload the program and keep those config in the JSON file to be loaded. I will get this error after call: config.Set("parent[0].child1Field1", 5):

key parent[0] elem must be map for set sub-value by remain path: parent[0].child1Field1

Any idea?

@inhere inhere reopened this Mar 23, 2024
@inhere inhere added the bug Something isn't working label Mar 23, 2024
@KiddoV
Copy link
Author

KiddoV commented Apr 17, 2024

Any update on this?

@inhere
Copy link
Member

inhere commented Apr 18, 2024

:( I've been quite busy lately, so no updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants