Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
This library offers a simple function to complete any prefix of a valid JSON string, in a way that makes it a valid JSON again (e.g. by closing all open brackets and quotes), in a minimal way.
There is only one function, json_autocomplete(json_prefix: str) -> str
, which takes a prefix of a valid JSON string and returns a valid JSON string that is the shortest possible completion of the prefix.
The heck did I develop this for? When streaming a response from a LLM like ChatGPT, where the model generates a JSON string, you can render it before the model is done generating the response.
Another use case could be when you want to allow the user to enter a JSON string, but you want to offer autocomplete suggestions. You can use this function to get the shortest possible completion of the prefix the user has entered, and then offer that as a suggestion.
>>> json_autocomplete('')
'null'
>>> json_autocomplete('n')
'null'
>>> json_autocomplete('tr')
'true'
>>> json_autocomplete('-')
'-0'
>>> json_autocomplete('2.')
'2.0'
>>> json_autocomplete('[')
'[]'
>>> json_autocomplete('{')
'{}'
>>> json_autocomplete('{"')
'{"": null}'
>>> json_autocomplete('{"a": 1, "b": 2')
'{"a": 1, "b": 2}'
pip install json-autocomplete
Then, simply import the function:
from json_autocomplete import json_autocomplete
json_autocomplete('{"a": 1, "b": 2')
After making any changes to either Cython files or C++ files, you must cythonize the files:
cythonize -i json_autocomplete/*.pyx
This will 1) compile the Cython files to C++ files, and 2) compile the C++ files to shared libraries.
Afterwards, you can install the package:
pip install .
FAQs
Autocomplete any prefix substring of a JSON to become valid
We found that json-autocomplete demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.