Skip to main content

Funções inteligentes para validação, limpeza e conversão de JSON em Python

Project description

📦 SmartJsonPy

SmartJsonPy é um pacote Python leve e poderoso para manipulação de JSON. Ele oferece funções para validação, limpeza, extração, deduplicamento e conversão de dados JSON. Ideal para preparação de dados, integrações com APIs e exportação para planilhas.


🧪 Testes

Execute os testes com pytest:

pytest tests/

🚀 Instalação

pip install SmartJsonPy

Requer: Python >= 3.7


✨ Funcionalidades

✅ Validação de JSON

from SmartJsonPy import validator

validator.is_valid_json_string('{"nome": "João"}')  # True
validator.is_valid_json_object({"id": 1})              # True
validator.has_required_keys({"id": 1}, ["id"])        # True
validator.is_json_schema_compatible({"id": 1}, {"id": int})  # True

🧹 Limpeza de dados

from SmartJsonPy import cleaner

data = {"a": 1, "b": None, "c": "", "d": []}
cleaner.remove_none_values(data)       # {"a": 1, "c": "", "d": []}
cleaner.remove_empty_values(data)      # {"a": 1}
cleaner.strip_whitespace_keys({" nome ": "Ana"})  # {"nome": "Ana"}

nested = {"x": {"y": {"z": None}}, "a": ["ok", {}]}
cleaner.clean_nested_dict(nested)  # {"a": ["ok"]}

🔍 Extração de dados

from SmartJsonPy import extractor

data = {"a": 1, "b": {"a": 2}, "c": [{"a": 3}, {"x": 9}]}
extractor.extract_keys(data)           # ['a', 'b', 'c', 'x']
extractor.extract_values_by_key(data, "a")  # [1, 2, 3]

🔁 Deduplicar dados

from SmartJsonPy import utils

# Dicionários duplicados
lst = [{"a": 1}, {"a": 1}, {"b": 2}]
utils.remove_duplicate_dicts(lst)  # [{"a": 1}, {"b": 2}]

# Itens duplicados
nums = [1, 2, 2, 3, 1]
utils.remove_duplicate_items(nums)  # [1, 2, 3]

🔄 Conversões entre string e JSON

from SmartJsonPy import utils

# JSON para string
d = {"nome": "João"}
utils.json_to_string(d)  # '{"nome": "João"}'

# String para JSON
s = '{"nome": "Maria"}'
utils.string_to_json(s)  # {'nome': 'Maria'}

📊 Conversão para formato de colunas (planilhas)

from SmartJsonPy import utils

lista = [
    {"name": "Roberto", "age": 45, "gender": "m"},
    {"name": "Joao", "age": 32, "gender": "m"},
    {"name": "Renata", "age": 39, "gender": "f"}
]

utils.convert_list_of_dicts_to_columns(lista)
# (
#   ('name', 'age', 'gender'),
#   ('Roberto', 'Joao', 'Renata'),
#   (45, 32, 39),
#   ('m', 'm', 'f')
# )

👨‍💻 Autor

Desenvolvido por Roberto Lima 🚀✨


💬 Contato


📄 Licença

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartjsonpy-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smartjsonpy-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file smartjsonpy-0.1.0.tar.gz.

File metadata

  • Download URL: smartjsonpy-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for smartjsonpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 356d1826ba674dedad28e4720825d0418e6dca41ae4a7ab9ef08a8868c56ddc1
MD5 7019857896eb234c6c109ebe495044aa
BLAKE2b-256 1ffb7dea27a78e7ce4c7b8addf3f8904f5a8700135aef236221a801ad78d8126

See more details on using hashes here.

File details

Details for the file smartjsonpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: smartjsonpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for smartjsonpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14e0934712d6258edfef31c7ad74ab58b97489b2969b41c8ae63f53f60aae622
MD5 fc1b4f02c565a4289bdf3ef454bb1c77
BLAKE2b-256 1283c321a1aceec2b0b612db434c9face2e66e7b4e7ffdb64a13541d03113828

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page