JSON:API support for Django REST framework

Overview JSON:API support for Django REST framework By default, Django REST framework will produce a response like: { “count”: 20, “next”: “http://example.com/api/1.0/identities/?page=3”, “previous”: “http://example.com/api/1.0/identities/?page=1”, “results”: [{ “id”: 3, “username”: “john”, “full_name”: “John Coltrane” }] } However, for an identity model in JSON:API format the response should look like the following: { “links”: { “prev”: “http://example.com/api/1.0/identities”, “self”: “http://example.com/api/1.0/identities?page=2”, “next”: “http://example.com/api/1.0/identities?page=3”, }, “data”: [{ “type”: “identities”, “id”: “3”, “attributes”: { “username”: “john”, “full-name”: “John Coltrane” } }], “meta”: { “pagination”: { “count”: […]

Read more

JSON Logging for Sanic in python

JSON Logging for Sanic The other day I was running some containers on Amazon’s ECS and logging to cloudwatch. I then learnt cloudwatch parses JSON logs so obviously I then wanted Sanic to log out JSON. Ideally this’ll be useful to people but if it isn’t, raise an issue and we’ll make it better 🙂 To install: pip install sanic-json-logging Look at examples/simple.py for a full working example, but this will essentially get you going import sanic from sanic_json_logging import […]

Read more

Declaratively specify how to extract elements from a JSON document

JMESPath JMESPath (pronounced “james path”) allows you to declaratively specify how to extract elements from a JSON document. For example, given this document: {“foo”: {“bar”: “baz”}} The jmespath expression foo.bar will return “baz”. JMESPath also supports: Referencing elements in a list. Given the data: {“foo”: {“bar”: [“one”, “two”]}} The expression: foo.bar[0] will return “one”. You can also reference all the items in a list using the * syntax: {“foo”: {“bar”: [{“name”: “one”}, {“name”: “two”}]}} The expression: foo.bar[*].name will return [“one”, […]

Read more

An Exploration of JSON Interoperability Vulnerabilities

JSON Interoperability Vulnerability Labs These are the companion labs to my research article “An Exploration of JSON Interoperability Vulnerabilities”. Lab 1: Free purchases in an E-commerce Application Key Collision Attacks: Inconsistent Duplicate Key Precedence Inconsistent Large Number Representations Lab 2: Privilege Escalation in a Multi-tenant Application Key Collision Attacks: Character Truncation These labs bind to host ports 5000-5004, by default. Attack Techniques 1. Key Collisions Inconsistent Duplicate Key Precedence {“qty”: 1, “qty”: -1} Character Truncation Truncation in last-key precedence parsers […]

Read more

Creates fake JSON files from a JSON schema

jsf Use jsf along with fake data generators to provide consistent and meaningful fake data for your system. Use jsf along with fake data generators to provide consistent and meaningful fake data for your system. Main Features Provides out of the box data generation from any JSON schema 📦 Extendable custom data providers using any lambda functions 🔗 Multi level state for dependant data (eg multiple objects sharing value, such as children with same surname) 🤓 Inbuilt validation of fake […]

Read more

Import Python modules from dicts and JSON formatted documents

Paker Paker is module for importing Python packages/modules from dictionaries and JSON formatted documents. It was inspired by httpimporter. Installation From PyPI pip install paker From source git clone https://github.com/desty2k/paker.git cd paker pip install . Usage In Python script You can import Python modules directly from string, dict or bytes (without disk IO). import paker import logging MODULE = {“somemodule”: {“type”: “module”, “code”: “fun = lambda x: x**2”}} logging.basicConfig(level=logging.NOTSET) if __name__ == ‘__main__’: with paker.loads(MODULE) as loader: # somemodule will […]

Read more

Import json files directly in your python scripts

direct-json-import Import json files directly in your python scripts. Install Install from git repository pip install git+https://github.com/zaghaghi/direct-json-import.git Use With the following json in a file named info.json. { “name”: “hamed”, “lastname”: “zaghaghi”, “repos”: [ “https://github.com/zaghaghi/direct-json-import” ] } you can directly import it as follows import info print(info.data) # {‘name’: ‘hamed’, ‘lastname’: ‘zaghaghi’, ‘repos’: [‘https://github.com/zaghaghi/direct-json-import’]} GitHub https://github.com/zaghaghi/direct-json-import    

Read more

A Python Based Utility for Processing GST-Return JSON Files to Multiple Formats

GSTR 1/2A Utility A Python Based Utility for Processing GST-Return JSON Files to Multiple Formats by Shan.tk Open Source GSTR 1/GSTR 2A JSON to Excel utility based on Python. Useful for Auditors in Verifying GSTR 1 Return Invoices with Ledgers Screenshots Currently Working Methods for Both GSTR 1/2A B2B Invoices B2B Credit Notes Exports B2C Sales B2B Amended Invoices To be Done B2C Amended Invoices HSN Summary If You are Interested in this Project. Pull Requests are Welcomed if it […]

Read more

Simple Python Library to convert JSON to XML

json2xml Simple Python Library to convert JSON to XML. Features It lets you convert json to xml in following ways: from a json string from a json file from an API that emits json data Usage The usage is simple: from json2xml import json2xml from json2xml.utils import readfromurl, readfromstring, readfromjson # get the xml from an URL that return json data = readfromurl(“https://coderwall.com/vinitcool76.json”) print(json2xml.Json2xml(data).to_xml()) # get the xml from a json string data = readfromstring( ‘{“login”:”mojombo”,”id”:1,”avatar_url”:”https://avatars0.githubusercontent.com/u/1?v=4″}’ ) print(json2xml.Json2xml(data).to_xml()) # get […]

Read more
1 2 3