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

python sdk? #124

Closed
yuanjie-ai opened this issue Apr 24, 2024 · 8 comments
Closed

python sdk? #124

yuanjie-ai opened this issue Apr 24, 2024 · 8 comments
Labels
question Further information is requested

Comments

@yuanjie-ai
Copy link

python sdk?

@josdejong josdejong added the question Further information is requested label Apr 24, 2024
@josdejong
Copy link
Owner

See #84 (comment)

@tybalex
Copy link

tybalex commented May 6, 2024

I don't think the python code from issue84 works as expected, for example:

x = '{"name": "John", "age": no"}'
repaired_json = JsonRepair(x).repair()
print(repaired_json)

gives me this error: Error: string index out of range.
while jsonrepair will fix it to {"name": "John", "age": "no"}

@josdejong
Copy link
Owner

Hm... so there is work to do there.

Maybe this can work via js2py? I tried it out but the library doesn't support python 3.12 unfortunately and throws errors. See PiotrDabkowski/Js2Py#324.

@josdejong
Copy link
Owner

I found PythonMonkey and that works like a charm:

  1. First, install the npm package in your project via npm install jsonrepair

  2. Install PythonMonkey via pip install pythonmonkey

  3. Use the libraries in a python script":

    import pythonmonkey
    
    jsonrepair = pythonmonkey.require('jsonrepair').jsonrepair
    
    json = "{name: 'John'}"
    repaired = jsonrepair(json)
    print(repaired) 
    # {"name": "John"}

@tybalex
Copy link

tybalex commented May 7, 2024

@josdejong yep this works!

@josdejong
Copy link
Owner

That's cool 😎 .

I've added a section in the readme describing how to use jsonrepair in Python: https://github.com/josdejong/jsonrepair?tab=readme-ov-file#python

I think this more or less removes the need for a Python port (unless it turns out to have performance issues or other limitations). Closing this issue now.

@emanuelevivoli
Copy link

This is just amazing! Thanks, for all the effort <3

@josdejong
Copy link
Owner

👍

Someone is also working on a Python port of the library, see: https://github.com/SelectedSolutionManagement/jsonrepair (as far as I know it's not yet published at pypi).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants