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

BugFix :: JSON Flatten is unable to handle a list of json objects #47

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

JeffLabonte
Copy link
Contributor

@JeffLabonte JeffLabonte commented Jun 29, 2024

Hello!

It is me again!

I noticed the example couldn't handle lists of JSON objects as well. I fixed it, and I made quite a mess last time I contributed, so I cleaned behind myself 😉 .

As you will be able to see in my example below, I went for a common way to annotate the element that is part of a list by identifying it with the index of the element of the list.

Example:

Before:

{
  "id": 1234,
  "content": {
    "id": 123,
    "name": {
      "first": "Dave",
      "middle": null
    },
    "addresses": [
      {
        "street":"someStreet",
        "appartments":[]
      },
      {
        "street":"someOtherStreet",
        "appartments":[ 1, 2, 3, 4 ]
      }
    ]
  },
  "data": [1, "fish", 2, "fish"],
  "more_data": {
    "id": 123,
    "empty": {},
    "name": {
      "first": "Bob",
      "middle": "Jr"
    }
  },
  "content": "test",
  "empty_again": {}
}

After:

{
  "id": 1234,
  "content.id": 123,
  "content.name.first": "Dave",
  "content.name.middle": null,
  "content.addresses.0.street": "someStreet",
  "content.addresses.0.appartments": [],
  "content.addresses.1.street": "someOtherStreet",
  "content.addresses.1.appartments": [1, 2, 3, 4],
  "data": [1, "fish", 2, "fish"],
  "more_data.id": 123,
  "more_data.empty": {},
  "more_data.name.first": "Bob",
  "more_data.name.middle": "Jr",
  "content": "test",
  "empty_again": {}
}

Thank you 😄

Copy link

netlify bot commented Jun 29, 2024

Deploy Preview for redpanda-labs-preview ready!

Name Link
🔨 Latest commit 72d9a53
🔍 Latest deploy log https://app.netlify.com/sites/redpanda-labs-preview/deploys/667f84769bd7f000087176f3
😎 Deploy Preview https://deploy-preview-47--redpanda-labs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@rockwotj rockwotj requested a review from voutilad July 15, 2024 14:06
Copy link
Collaborator

@rockwotj rockwotj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. I think there is a (probably strange) edge case to handle, otherwise it looks great!


default:
return isNodeFlattened
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we returning early here? Does this end up skipping over elements if there are heterogeneous lists? I.E.

[
  "foo",
  {"a":4},
  5,
]

I think the above case will drop the 5 value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above doesn't drop values, but it doesn't flatten the {"a": 4} Object, either. If the first element ("foo") is removed, it will drop the 5.

I'm conflicted on what the correct approach should be here. My original intent was to provide a close to drop in replacement for the Kafka Connect Flatten SMT. I believe the Flatten SMT supports heterogeneous Array flattening, but requires a schema. Maybe that's the correct approach here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't have much time to put in this PR lately. It has been a moment since I opened this PR, I don't remember why, to be honest. I will look it up as well when I will have a moment.

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.

3 participants