🔍 Code Extractor

class V4JsonFormat

Maturity: 46

V4JsonFormat is a class that implements OData V4 JSON format specifications, managing metadata levels, IEEE754 compatibility, and streaming options for JSON serialization.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/runtime/odata/v4/json_format.py
Lines:
5 - 38
Complexity:
moderate

Purpose

This class provides a concrete implementation of OData V4 JSON format handling, extending ODataJsonFormat to support V4-specific features. It manages metadata levels (minimal, full, none), controls IEEE754-compatible number serialization (Int64 and Decimal as strings), and configures streaming behavior. The class generates appropriate media type strings and provides properties for accessing OData V4 control information like collection values, next links, and type metadata.

Source Code

class V4JsonFormat(ODataJsonFormat):
    """JSON format (V4)"""

    def __init__(self, metadata_level=ODataV4MetadataLevel.Minimal):
        super(V4JsonFormat, self).__init__(metadata_level)
        """The IEEE754Compatible format parameter indicates that the service MUST serialize Edm.Int64 and
        Edm.Decimal numbers as strings."""
        self.IEEE754Compatible = False
        self.streaming = False

    @property
    def metadata_type(self):
        return "@odata.type"

    @property
    def collection(self):
        return "value"

    @property
    def collection_next(self):
        return "@odata.nextLink"

    @property
    def media_type(self):
        return "application/json;odata.metadata={0};odata.streaming={1};IEEE754Compatible={2}".format(
            self.metadata_level, self.streaming, self.IEEE754Compatible
        )

    @property
    def include_control_information(self):
        return (
            self.metadata_level == ODataV4MetadataLevel.Minimal
            or self.metadata_level == ODataV4MetadataLevel.Full
        )

Parameters

Name Type Default Kind
bases ODataJsonFormat -

Parameter Details

metadata_level: Specifies the OData V4 metadata level for JSON responses. Accepts ODataV4MetadataLevel enum values (Minimal, Full, or None). Defaults to ODataV4MetadataLevel.Minimal. Controls how much metadata is included in JSON responses - Minimal includes essential metadata, Full includes all metadata, None excludes metadata.

Return Value

Instantiation returns a V4JsonFormat object configured with the specified metadata level. The object provides properties that return strings (metadata_type, collection, collection_next, media_type) and a boolean (include_control_information) for controlling JSON format behavior.

Class Interface

Methods

__init__(self, metadata_level=ODataV4MetadataLevel.Minimal)

Purpose: Initializes a V4JsonFormat instance with specified metadata level and default IEEE754 and streaming settings

Parameters:

  • metadata_level: ODataV4MetadataLevel enum value specifying the metadata verbosity (Minimal, Full, or None). Defaults to Minimal.

Returns: None (constructor)

@property metadata_type(self) -> str property

Purpose: Returns the OData V4 JSON property name used for type metadata

Returns: String '@odata.type' - the standard OData V4 property name for type information

@property collection(self) -> str property

Purpose: Returns the OData V4 JSON property name used for collection values

Returns: String 'value' - the standard OData V4 property name for collection data

@property collection_next(self) -> str property

Purpose: Returns the OData V4 JSON property name used for pagination next links

Returns: String '@odata.nextLink' - the standard OData V4 property name for pagination

@property media_type(self) -> str property

Purpose: Generates the complete media type string for HTTP Content-Type header including metadata level, streaming, and IEEE754 compatibility parameters

Returns: Formatted string like 'application/json;odata.metadata=minimal;odata.streaming=False;IEEE754Compatible=False' with actual values based on instance configuration

@property include_control_information(self) -> bool property

Purpose: Determines whether OData control information should be included in JSON output based on metadata level

Returns: Boolean True if metadata_level is Minimal or Full, False otherwise

Attributes

Name Type Description Scope
IEEE754Compatible bool When True, forces serialization of Edm.Int64 and Edm.Decimal numbers as strings for compatibility with clients that cannot handle large numbers. Defaults to False. instance
streaming bool Indicates whether streaming mode is enabled for the JSON format. When True, responses may be streamed. Defaults to False. instance
metadata_level ODataV4MetadataLevel Inherited from parent class. Stores the metadata level (Minimal, Full, or None) that controls how much metadata is included in JSON responses. instance

Dependencies

  • office365.runtime.odata.json_format
  • office365.runtime.odata.v4.metadata_level

Required Imports

from office365.runtime.odata.json_format import ODataJsonFormat
from office365.runtime.odata.v4.metadata_level import ODataV4MetadataLevel

Usage Example

from office365.runtime.odata.json_format import ODataJsonFormat
from office365.runtime.odata.v4.metadata_level import ODataV4MetadataLevel
from office365.runtime.odata.v4.json_format import V4JsonFormat

# Create with default minimal metadata
format_minimal = V4JsonFormat()

# Create with full metadata
format_full = V4JsonFormat(metadata_level=ODataV4MetadataLevel.Full)

# Configure IEEE754 compatibility for large numbers
format_minimal.IEEE754Compatible = True
format_minimal.streaming = True

# Access format properties
media_type = format_minimal.media_type
# Returns: 'application/json;odata.metadata=minimal;odata.streaming=True;IEEE754Compatible=True'

metadata_field = format_minimal.metadata_type  # '@odata.type'
collection_field = format_minimal.collection  # 'value'
next_link_field = format_minimal.collection_next  # '@odata.nextLink'

# Check if control information should be included
if format_minimal.include_control_information:
    print('Control information will be included in response')

Best Practices

  • Set IEEE754Compatible to True when working with clients that cannot handle large integers (Edm.Int64) or decimals (Edm.Decimal) natively, as this forces serialization as strings.
  • Choose the appropriate metadata_level based on client needs: Minimal for most cases, Full when clients need complete metadata, None for minimal payload size.
  • The streaming property should be set to True when dealing with large datasets that benefit from streaming responses.
  • Properties are read-only and computed dynamically, so accessing them multiple times will recompute values - cache results if needed for performance.
  • The include_control_information property determines whether OData control information is included; it returns True for Minimal and Full metadata levels.
  • This class is immutable after instantiation except for IEEE754Compatible and streaming attributes, which can be modified as needed.
  • Use the media_type property to set HTTP Content-Type headers when sending OData V4 JSON responses.

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class ODataJsonFormat 73.1% similar

    Abstract base class defining the interface for OData JSON format implementations with configurable metadata levels.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/runtime/odata/json_format.py
  • class ODataV4MetadataLevel 65.5% similar

    A class that defines constants for OData V4 metadata level options used in HTTP Accept headers or $format query parameters.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/runtime/odata/v4/metadata_level.py
  • class ODataV4Reader 65.1% similar

    ODataV4Reader is a specialized reader class for parsing OData v4 metadata documents, extending the base ODataReader with v4-specific XML namespace configurations.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/runtime/odata/v4/metadata_reader.py
  • class ODataV4BatchRequest 60.6% similar

    A class that handles OData V4 JSON batch requests, allowing multiple OData operations to be bundled and executed in a single HTTP request.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/runtime/odata/v4/batch_request.py
  • class JsonLightFormat 60.1% similar

    JSON Light format for SharePoint Online/One Drive for Business

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/runtime/odata/v3/json_light_format.py
← Back to Browse