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

Simple json encoding example does not export all data properly #71

Closed
MarcinOrlowski opened this issue Mar 5, 2019 · 6 comments
Closed

Comments

@MarcinOrlowski
Copy link

MarcinOrlowski commented Mar 5, 2019

I am trying to parse my bank's MT940 data with your library and example of JSON encoding is producing different results than "plain" data dump. This is what I see with plain dump:

{'amount': <-21.99 PLN>,
 'bank_reference': None,
 'currency': 'PLN',
 'customer_reference': '00000013586',
 'date': Date(2019, 3, 3),
 'entry_date': Date(2019, 3, 3),
 'extra_details': '',
 'funds_code': None,
 'guessed_entry_date': Date(2019, 3, 3),
 'id': 'S114',
 'status': 'D',
 'transaction_details': '114\n'
                        '114~00B114ZAKUP PRZY UŻYCIU KARTY\n'
                        '~20SALAD STORY SZCZECI/SZCZECI\n'
                        '~21N\n'
                        '~22                DATA TRANSA\n'
                        '~23KCJI: 2019-03-01\n'
                        '~24\n'
                        '~25\n'
                        '~26\n'
                        '~27\n'
                        '~28\n'
                        '~29\n'
                        '~30\n'
                        '~31\n'
                        '~32\n'
                        '~33\n'
                        '~34114\n'
                        '~38PL\n'
                        '~62\n'
                        '~63'}

and this is what JSON dump example outputs:

{
    "status": "D",
    "funds_code": null,
    "amount": null,
    "id": "S114",
    "customer_reference": "00000013586",
    "bank_reference": null,
    "extra_details": "",
    "currency": "PLN",
    "date": null,
    "entry_date": null,
    "guessed_entry_date": null,
    "transaction_details": "114\n114~00B114ZAKUP PRZY U\u017bYCIU KARTY\n~20SALAD STORY SZCZECI/SZCZECI\n~21N\n~22                DATA TRANSA\n~23KCJI: 2019-03-01\n~24\n~25\n~26\n~27\n~28\n~29\n~30\n~31\n~32\n~33\n~34114\n~38PL\n~62\n~63"
}

And relevant part of the source file:

:61:1903030303D21,99S11400000013586
:86:114
:86:114~00B114ZAKUP PRZY UŻYCIU KARTY
~20SALAD STORY SZCZECI/SZCZECI
~21N    
~22                DATA TRANSA
~23KCJI: 2019-03-01
~24
~25
~26
~27
~28
~29
~30
~31
~32
~33
~34114
~38PL
~62
~63
@wolph
Copy link
Owner

wolph commented Mar 5, 2019

Can you show a bit of code to illustrate how you are dumping both?

While I do have some yaml loading/dumping in the code, I haven't tested with json loading/dumping so far. The yaml examples can be found here, they're used by the test system: https://github.com/WoLpH/mt940/blob/develop/tests/test_sta_parsing.py#L30-L39

My guess would be that the easiest way to get it working is by overriding JSONEncoder.default to support these types: https://docs.python.org/3/library/json.html#json.JSONEncoder.default

@MarcinOrlowski
Copy link
Author

MarcinOrlowski commented Mar 5, 2019

I am using examples from README. Literally as-is.

@wolph
Copy link
Owner

wolph commented Mar 5, 2019

You're right. That demo is lacking quite a bit. I've updated the code in the readme to be a bit more useful :)

Does that help?

@MarcinOrlowski
Copy link
Author

MarcinOrlowski commented Mar 5, 2019

Thanks. No, it's still not work properly as all the dates (date, entry_date, guessed_entry_date) values are not in JSON dump.

@wolph
Copy link
Owner

wolph commented Mar 6, 2019

I've created a json encoder which should handle all of the types for you. That should help a bit :)

import json
import mt940


transactions = mt940.parse('tests/jejik/abnamro.sta')

print(json.dumps(transactions, indent=4, cls=mt940.JSONEncoder))

@MarcinOrlowski
Copy link
Author

That works perfect. Thank you!

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

2 participants