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'}

🔄 Transformação de Dados

from SmartJsonPy import transformer

# JSON para YAML
data = {"nome": "João", "idade": 30}
yaml_str = transformer.json_to_yaml(data)
# name: João
# age: 30

# JSON para XML
xml_str = transformer.json_to_xml(data, root_name="pessoa")
# <?xml version="1.0" encoding="utf-8"?>
# <pessoa>
#   <nome>João</nome>
#   <idade>30</idade>
# </pessoa>

# JSON para CSV
lista = [
    {"nome": "João", "idade": 30},
    {"nome": "Maria", "idade": 25}
]
csv_str = transformer.json_to_csv(lista)
# nome,idade
# João,30
# Maria,25

# Achatamento de JSON
nested = {"a": {"b": {"c": 1}}}
flat = transformer.flatten_json(nested)
# {"a.b.c": 1}

# Desachatamento de JSON
nested = transformer.unflatten_json({"a.b.c": 1})
# {"a": {"b": {"c": 1}}}

📊 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-1.1.1.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

smartjsonpy-1.1.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smartjsonpy-1.1.1.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for smartjsonpy-1.1.1.tar.gz
Algorithm Hash digest
SHA256 60322b82ab97cf726484878e1f18a87a16c65524163e0a8263ba0c0ce2247df0
MD5 9dd2147e9cad97d64c696fc6f84c94ed
BLAKE2b-256 1e0023e4f22761f0c99e0988f94f4ade36dc2e5bb2d6bdabd3b235241b2ef7ce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smartjsonpy-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for smartjsonpy-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6ae2624bcbbf60fb686f216cce55c39f71693aef2cfbce6a72b6ee9d27c4299e
MD5 17c4a29876d56f2ec34d9addf10f57d9
BLAKE2b-256 fa003b67111e4bbc3fec5366923cd759b55f61d3177ff3d8e0b327f4e5df33b3

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