JSON message organization method based on dynamic self-defined format of extensible markup language
Patent Information
- Application Number
- CN202610801199.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-04
- Publication Date
- 2026-10-09
AI Technical Summary
[0013]综上所述,本发明实施例提供的一种基于可扩展标记语言的动态自定义格式的JSON报文组织方法,与现有技术相比,解决了基于传统JSON报文的结构与映射逻辑常采用硬编码固化,导致字段或结构变更时需要间隙修改底层代码并重新部署缺乏扩展性与接口架构的灵活针对上述技术问题,本发明通过引入可扩展标记语言格式的结构模板,实现了报文结构与底层业务代码的深度解耦其技术效果主要在:系统能够支持在运行时结构模板动态解析并生成目标JSON结构对象,不需要修改及重新发布证明程序代码即可敏捷响应系统间不同的数据格式需求;同时,通过模板内配置的条件逻辑、循环控制及高速转换机制,能够高效灵活、地处理复杂的结构与多层循环,显着降低了多项数据交换和多协议场景集成下的系统维护成本,极大提升了数据交换流转的扩展性与接口设备效率。
Smart Images

Figure CN122884716A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method for organizing JSON messages based on a dynamically customized format using Extensible Markup Language. Background Technology
[0002] With the widespread application of architecture and microservice technologies, JSON messages, with their improved lightweight and high availability, have become the mainstream data carrier for data exchange between systems and for integration of devices and multiple protocols. However, in traditional data interaction implementations, the topology and data mapping logic of JSON messages are usually hard-coded in the header business code. When faced with changing business requirements or different data models between systems, if the field names, number of segmentation layers, or loop structure of the message are adjusted in time, technicians must make intermittent modifications, recompile, and redeploy the underlying code. This results in a lack of system flexibility and scalability, making it difficult to achieve agile responses to dynamically customized message formats. Therefore, how to provide a method that can decouple the message structure from the business code and achieve dynamic and flexible JSON message organization at system runtime is a technical problem that urgently needs to be solved in the field of formatted information processing. Summary of the Invention
[0003] To address the aforementioned issues, this invention proposes a method for organizing JSON messages using a dynamically customized format based on Extensible Markup Language (Extreme Markup Language). The method includes: obtaining a structure template in Extreme Markup Language format, the structure template containing field attributes and mapping rules for input data; parsing the structure template to construct a corresponding tree-like data model; extracting corresponding target data values from the input source data object according to the mapping rules in the structure template; generating a target JSON structure object through recursive processing based on the node types defined in the structure template and the extracted target data values; and serializing the target JSON structure object to output a standard JSON message.
[0004] Furthermore, the node types defined in the structure template include index nodes, object nodes, and index nodes.
[0005] Furthermore, the parsing of the structure template includes: parsing the node structure of the structure template using a Document Object Model parser or an event-based Simple Extensible Markup Language (SEXPLAIN) access interface parser.
[0006] Furthermore, the field attributes include field name, field type, value retrieval path, conditional logic, and loop control information.
[0007] Furthermore, the step of extracting the corresponding target data value from the input source data object according to the mapping rules in the structure template includes: extracting the target data value from the source data object using dot path or Extensible Markup Language path language expression.
[0008] Furthermore, the structure template is configured with conditional expressions and loop control logic, including: dynamically controlling and outputting the corresponding fields in the target JSON structure object according to the conditional expressions and the loop control logic.
[0009] Furthermore, the step-by-step processing to generate the target JSON structure object includes: constructing a loop staircase or a branch gradient for the tree structure, staircase loop structure, and conditional branch structure in the tree data model.
[0010] Furthermore, the method also includes: when generating the target JSON structure object, calling a default format conversion function to perform data type conversion or data formatting processing on the extracted target data values.
[0011] Furthermore, the output standard JSON message includes: sending the serialized standard JSON message to an external interface caller, or storing the standard JSON message in a default file system.
[0012] Furthermore, the method evaluates data exchange and interface configuration protocol integration scenarios between systems.
[0013] In summary, the JSON message organization method based on a dynamically customized format using Extensible Markup Language (Extreme Markup Language) provided by this invention addresses the shortcomings of traditional JSON message structures and mapping logic, which are often hard-coded and fixed. This results in gaps in scalability and interface architecture flexibility, requiring modification of underlying code and redeployment when fields or structures change. To address these issues, this invention introduces an Extensible Markup Language (Extreme Markup Language) format structure template, achieving deep decoupling between message structure and underlying business code. Its main technical effects are: the system can dynamically parse the structure template and generate the target JSON structure object at runtime, responding quickly to different data format requirements between systems without modifying or redeploying the proof program code; simultaneously, through conditional logic, loop control, and high-speed conversion mechanisms configured within the template, it can efficiently and flexibly handle complex structures and multi-layered loops, significantly reducing system maintenance costs in multi-data exchange and multi-protocol integration scenarios, and greatly improving the scalability of data exchange and the efficiency of interface devices. Attached Figure Description
[0014] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0015] Figure 1 This is a flowchart provided in an exemplary embodiment of the present invention. Detailed Implementation
[0016] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0017] This embodiment provides a method for organizing JSON messages with a dynamically customizable format based on Extensible Markup Language (Extensible Markup Language). The method includes: Step S10: Obtain a structure template in Extensible Markup Language (XML) format, the structure template containing field attributes and mapping rules for the input data; Step S20: Parse the structure template to construct the corresponding tree-like data model; Step S30: Extract the corresponding target data value from the input source data object according to the mapping rules in the structure template; Step S40: Based on the node types defined in the structure template and the extracted target data values, generate the target JSON structure object through recursive processing; Step S50: Serialize the target JSON structure object to output a standard JSON message.
[0018] By introducing a structure template in the Extensible Markup Language (Extreme Markup Language) format, deep coupling between the JSON message structure and the underlying business code is achieved. The system can generate dynamically and efficiently parse and target JSON messages at runtime simply by adjusting the template, without needing to redeploy the program code. This significantly improves the system's responsiveness to changing message format requirements and enhances its scalability. Specifically, the node types defined in the structure template include index nodes, object nodes, and index nodes. By explicitly limiting the node types in the structure template to fields, objects, and backups, full coverage of the basic components of standard JSON data messages is achieved, ensuring that the method can accurately and completely map and reconstruct various standard JSON structures.
[0019] Specifically, the parsing of the structure template includes: parsing the node structure of the structure template using a Document Object Model (DOM) parser or an event-based Simple Extensible Markup Language (SXML) access interface parser. Using a DOM parser or an event-based SXML access interface parser provides highly reliable and efficient node parsing support for structure templates of different sizes or performance requirements, ensuring that an accurate tree-like data model can be stably constructed in memory during system runtime.
[0020] Specifically, the field attributes include field name, field type, value retrieval path, conditional logic, and loop control information.
[0021] Specifically, extracting the corresponding target data value from the input source data object according to the mapping rules in the structure template includes: The target data value is extracted from the source data object using dotted paths or Extensible Markup Language (XML) path expressions.
[0022] By using dot-matrix paths or Extensible Markup Language (Extreme Markup Language) path expressions, the mechanism for extracting target scores from input source data objects is standardized and improved. It can achieve accurate positioning for both rolling data and deep imprint data, avoiding the tedious process of writing custom extraction logic for complex source data.
[0023] Specifically, the structure template is configured with conditional expressions and loop control logic, including: dynamically controlling and outputting the corresponding fields in the target JSON structure object according to the conditional expressions and the loop control logic.
[0024] By introducing conditional expressions and loop control logic into the structure template, the final field output of the message can be dynamically controlled according to the actual source data content, giving the message generation process a strong ability to refactor business logic.
[0025] Furthermore, the step-by-step processing to generate the target JSON structure object includes: constructing a loop staircase or a branch gradient for the tree structure, staircase loop structure, and conditional branch structure in the tree data model.
[0026] By adopting a general loop or branch loop construction mechanism, the technical pain point of slow processing of complex structures such as multi-layer, multi-dimensional array loops in traditional hard coding is completely solved, ensuring the accuracy and integrity of the structure construction regardless of the structural depth or logical branching of the target message.
[0027] Specifically, the method further includes: when generating the target JSON structure object, calling a default format conversion function to perform data type conversion or data formatting processing on the extracted target data values. Embedding format conversion within the streaming process of generating the target JSON structure object achieves synchronous flow of data extraction, data cleaning, and type organization. Adding additional data structures or post-processing modules to the front end effectively reduces system resource overhead.
[0028] Furthermore, the output standard JSON message includes: sending the serialized standard JSON message to an external interface caller, or storing the standard JSON message in a default file system.
[0029] Furthermore, the method evaluates data exchange and interface configuration protocol integration scenarios between systems.
[0030] For components that are functionally identical or similar, existing mature devices can be used for replacement, and the implementation method is not limited to the structure shown in this specification.
[0031] The present invention can also be implemented in the form of software, hardware, or a combination of software and hardware; wherein the software can be stored in a computer-readable medium and executed by a processor to perform the corresponding function.
[0032] Applicable computer-readable media include, but are not limited to, hard disks, flash memory, read-only memory (ROM), random access memory (RAM), and other media capable of storing program code.
[0033] The execution order of the steps described in the flowchart or logic block diagram can be adjusted or parallelized as needed, provided that it does not affect the implementation of the function.
[0034] The accompanying drawings referenced in this specification are for illustrative purposes only. Their dimensions, scale, or colors may be adjusted according to actual production needs. The reference numerals in the drawings should not be construed as limiting the scope of protection.
[0035] All the technical features disclosed in this invention can be combined in any way to form an interactive or collaborative structure, as long as the combination does not contradict each other or conflict with the technology.
[0036] Although embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations all fall within the scope of protection claimed by the present invention.
Claims
1. A method for organizing JSON messages with a dynamically customizable format based on Extensible Markup Language, characterized in that, The method includes: Obtain a structure template in Extensible Markup Language (XML) format, the structure template containing field attributes and mapping rules for the input data; The structure template is parsed to construct the corresponding tree-like data model; According to the mapping rules in the structure template, extract the corresponding target data value from the input source data object; Based on the node types defined in the structure template and the extracted target data values, a target JSON structure object is generated through recursive processing. The target JSON structure object is serialized to output a standard JSON message.
2. The method according to claim 1, characterized in that, The node types defined in the structure template include index nodes, object nodes, and index nodes.
3. The method according to claim 1, characterized in that, The parsing structure template includes: The node structure of the structure template is parsed using a Document Object Model parser or an event-based Simple Extensible Markup Language (SEXPLAIN) access interface parser.
4. The method according to claim 1, characterized in that, The field attributes include field name, field type, value retrieval path, conditional logic, and loop control information.
5. The method according to claim 1, characterized in that, The step of extracting the corresponding target data value from the input source data object according to the mapping rules in the structure template includes: The target data value is extracted from the source data object using dotted paths or Extensible Markup Language (XML) path expressions.
6. The method according to claim 1, characterized in that, The structure template is configured with conditional expressions and loop control logic, including: dynamically controlling and outputting the corresponding fields in the target JSON structure object according to the conditional expressions and the loop control logic.
7. The method according to claim 6, characterized in that, The step-by-step processing to generate the target JSON structure object includes: For the tree structure, staircase loop structure, and conditional branch structure in the tree data model, perform loop staircase construction or branch gradient construction.
8. The method according to claim 1, characterized in that, The method further includes: When generating the target JSON structure object, the default format conversion function is called to perform data type conversion or data formatting on the extracted target data values.
9. The method according to claim 1, characterized in that, The output standard JSON message includes: The serialized standard JSON message is sent to the external interface caller, or the standard JSON message is stored in the default file system.
10. The method according to claim 1, characterized in that, The method evaluates data exchange and interface configuration protocol integration scenarios between systems.