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

JSON.class.php: Simple JSON export to generate nested objects #375

Merged
merged 1 commit into from Apr 16, 2016

Conversation

tohagan
Copy link
Contributor

@tohagan tohagan commented Apr 15, 2016

When field names contain "." delimiters and a JSON | Simple export is selected, then nested objects will be generated corresponding to the structure of the fields names. The only restriction is that fields related to the same object must be sequential.

Example 2 Field Names

  • name.first
  • name.last
  • address.0
  • address.1

Generates:

[
    {
        "name": {
            "first": "Rahim",
            "last": "Wyatt"
        },
        "address": {
            "0": "Ap #496-4933 Non, Street",
            "1": "190-7424 Malesuada Street"
        }
    },
    {
        "name": {
            "first": "Emi",
            "last": "King"
        },
        "address": {
            "0": "5331 Lacinia. Avenue",
            "1": "486-7654 Nisl Road"
        }
    }
]

Example 2: 3-level nested JSON

Field names ... All "Email" type

  • a
  • b.c
  • b.d.e
  • b.d.f
  • b.p.a
  • b.p.b

Generates:

[
    {
        "a": "et.commodo@amet.org",
        "b": {
            "c": "vestibulum.neque.sed@nuncsedlibero.org",
            "d": {
                "e": "ac@musAeneaneget.ca",
                "f": "tellus.Suspendisse@etpedeNunc.ca"
            },
            "p": {
                "a": "est.ac@nostra.ca",
                "b": "et.tristique@rutrum.org"
            }
        }
    },
    {
        "a": "sit.amet.ante@varius.com",
        "b": {
            "c": "et@neque.net",
            "d": {
                "e": "lacus.Quisque@Nullatempor.edu",
                "f": "ac@sem.edu"
            },
            "p": {
                "a": "libero.dui.nec@sit.ca",
                "b": "nec@malesuada.com"
            }
        }
    }
]

…ts when field names contain "." delimiters. Nested fields must be sequential.
@tohagan tohagan changed the title JSON.class.php: Simple JSON export can now generate nested JSON JSON.class.php: Simple JSON export to generate nested JSON Apr 15, 2016
@tohagan tohagan changed the title JSON.class.php: Simple JSON export to generate nested JSON JSON.class.php: Simple JSON export to generate nested objects Apr 15, 2016
@benkeen
Copy link
Owner

benkeen commented Apr 15, 2016

Damn @tohagan, this is brilliant! I wish I'd thought of this.

Give me a little time to check it over & I'll merge it in. Excellent idea + work.

@benkeen benkeen merged commit 3a0c7f9 into benkeen:master Apr 16, 2016
@benkeen
Copy link
Owner

benkeen commented Apr 16, 2016

Great stuff. Merged. Technically it may introduce a little backward incompability for people using periods in their field names, but I think since it's so specific, and potentially so useful, it's well worth adding.

Also, since this is very much a hidden feature (not obvious to the user as they use the tool), what I'm going to do is add your documentation notes to the JSON export type readme file, and update the core documentation to mention it too.

Thanks again @tohagan.

@benkeen benkeen added this to the 3.2.5 milestone Apr 16, 2016
@tohagan
Copy link
Contributor Author

tohagan commented Apr 21, 2016

Glad you like it. I needed nested objects for an app I'm building and thought it good manners to thank you (by contributing) for open sourcing your wonderfully useful app.

I did consider making this ...

  • address.0
  • address.1

generate this ...

    "address": {
          0: "5331 Lacinia. Avenue",
          1: "486-7654 Nisl Road"
    }

or maybe even this ....

    "address": [
          "5331 Lacinia. Avenue",
          "486-7654 Nisl Road"
    ]

This would be a breaking change and bit more work of course.

@benkeen
Copy link
Owner

benkeen commented Apr 21, 2016

I was thinking something along those lines, too - like address[0] would signify an array. Something for down the road. :)

@tohagan
Copy link
Contributor Author

tohagan commented Apr 22, 2016

2 more observations ...

  1. You could make this feature more obvious in the UI by offering it as a different JSON export option (keeping the old one and add this as a new export plugin).
  2. I noticed that the Language exports might also want nesting like this (Javascript, C#, Ruby, Perl etc). The rendering algorithm I used might come in handy for these.

@conradhagemans
Copy link
Contributor

I guess even for CSV export we could use this. Exporting the related data to a separate file.

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.

None yet

3 participants