- JSON Views in Codejig App Builder
JSON Views in Codejig App Builder
JSON Views in Codejig App Builder
Overview
JSON Views in Codejig App Builder allow developers to manage how data objects are serialized into JSON format. This serialization is crucial when creating APIs, integrating with external services, or exporting data, as it controls the structure and content of the JSON data exchanged.
Key Features
Field Selection and Ordering
- Include/Exclude Fields: Choose specific fields from a data type to be included in the JSON output.
- Ordering: Define the order in which fields should appear in the serialized JSON.
Comprehensive Configuration
- Primitive Fields and Complex Types:
Extend JSON views to handle both simple and complex types, managing nested structures efficiently.
- Formatting Primitive Fields: When dealing with primitive data types (like dates, numbers, and strings), JSON views allow you to specify formatting options. For instance, dates can be formatted in various international standards, and numbers can be adjusted to include grouping symbols or decimal places, ensuring that the data is serialized in a way that fits the intended user audience or system integration.
- Complex Type Serialization Options: For complex types, several serialization options are available:
- Full JSON Object: Serialize the entire complex object with all its fields according to the defined JSON view.
- Primitive Field Representation: Extract a specific identifying field (like a unique ID or name) to represent the complex type simply, which can be useful for reducing payload size.
- Reference Mode: Serialize as a reference, using an ID or link, which is optimal when the actual content of the complex type is not needed but the relationship is.
- Text view: Serialize complex type as one of its text views.
- Handling Nested Complex Types: Nested structures are managed through hierarchical JSON views. This means you can define separate JSON views for sub-entities and include them in the parent entity's view. This approach ensures that nested objects follow their serialization rules while maintaining a coherent structure within the parent JSON output. For example, a 'Customer Order' entity might serialize its 'Product Items' as a nested JSON array, each item following its JSON view for consistency and completeness.
- Renaming Fields: Customize field names in the JSON output to align with external requirements or naming conventions.
Multiple Views Support
- Create Multiple Views: Define different JSON views for the same data type to cater to varying needs across different APIs or parts of an application.
Integration with API Functions
- Input/Output Views: Specify JSON views when defining API functions to ensure that data passed in and out of APIs is consistently formatted.
Use Cases
APIs and External Integrations
- Retrieving Data: Use JSON views to structure data retrieval, ensuring that API consumers receive data in the expected format.
- Submitting Data: Ensure incoming JSON data is correctly mapped to internal entity fields, using JSON views to parse JSON payloads.
Data Export/Import
- Data Export: Define JSON views to format data appropriately for exporting to third-party systems.
- Data Import: Employ structured parsing of incoming JSON to convert it into data entries or entities within the application.
Implementation Steps
Creating JSON Views
- Access Views: Navigate to the data type for which you want to create or manage a JSON view.
- Define Fields: Select the fields you want included in the JSON view and arrange their order.
- Configure Properties: Set additional properties such as field names, serialization format, and complex type handling.
Using JSON Views in API Functions
- Define API Functions: Create functions using Codejig App Builder to expose functionalities externally.
- Set Input/Output Views: In the API function definition, specify JSON views for input and output types to handle serialization.
Example Code and Implementation
For practical examples of JSON Views in action within the Codejig environment, refer to the API Demo. This demo illustrates how JSON views are used to manage API interactions, providing insight into setting up and using these views effectively.
Advantages
- Consistency: JSON views ensure consistent data structure across different parts of the application and between systems.
- Efficiency: Reduce data payload size by selecting only necessary fields.
- Flexibility: Maintain multiple JSON views for the same data type to support various use cases or clients.
Conclusion
JSON Views in Codejig App Builder are an essential feature for managing how data is shared and received, helping to streamline API creation and integration, ensuring that data is consistently formatted, and aligning with business and technical requirements.