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

Lakify hierarchical JSON nesting function omits free-floating text when other children are present #291

Closed
akmiller01 opened this issue Oct 18, 2023 · 1 comment

Comments

@akmiller01
Copy link
Contributor

The recursive json nesting function of lakify will omit free-floating text when other children are present. For e.g.

    <iati-activity>
        Floating text
        <iati-identifier>ACT-1</iati-identifier>
    </iati-activity>

Would be serialized as:

{
  "iati-activity": [
    {
      "iati-identifier": [
        {
          "text()": "ACT-1"
        }
      ]
    }
  ]
}

Where one might expect:

{
  "iati-activity": [
    {
      "text()": "Floating text",
      "iati-identifier": [
        {
          "text()": "ACT-1"
        }
      ]
    }
  ]
}

This is because this floating text is not captured by element.text. It is, however, captured by element.itertext and could be derived like so:

inner_text = ''.join([inner_string.strip() for inner_string in element.itertext(tag=element.tag)])

Discovered while writing tests in PR #289

@akmiller01
Copy link
Contributor Author

Fixed with PR #292

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

No branches or pull requests

1 participant