JSON data conversion method and device

The JSON data conversion method, which utilizes pre-compilation technology and a dual-mode conversion mechanism, solves the flexibility and performance issues of data conversion between heterogeneous systems, achieving efficient and maintainable data integration and is suitable for flexible processing of complex data structures.

CN122019652APending Publication Date: 2026-05-12SHUSHU INFORMATION TECH (SHANGHAI) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHUSHU INFORMATION TECH (SHANGHAI) CO LTD
Filing Date
2026-02-04
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

Existing technologies suffer from poor flexibility, low performance, and difficulty in maintaining JSON data conversion between heterogeneous systems.

Method used

It adopts a JSON data transformation method based on configuration and expression engine, generates reusable script instances through pre-compilation technology, and combines template-driven and direct mapping dual-mode transformation mechanism to achieve low-code and high-efficiency data integration.

Benefits of technology

It significantly improves conversion performance, enhances the system's versatility and applicability, strengthens maintainability and scalability, and supports flexible processing of complex data structures.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122019652A_ABST
    Figure CN122019652A_ABST
Patent Text Reader

Abstract

The invention discloses a JSON data conversion method and device. The method comprises the steps that a conversion configuration file is received and comprises a field mapping rule list, and each field mapping rule defines a source path, a conversion expression and a target path; analyzing the source path and the target path, and compiling the conversion expression to generate a script instance; receiving source JSON data to be converted, and determining a plurality of field mapping rules corresponding to the plurality of fields; whether a final result template is defined in the conversion configuration file or not is determined, if yes, a template drive conversion mode is entered, and if not, a direct mapping conversion mode is entered; generating target JSON data according to the template mapping rule and the multiple field mapping rules in the template driving conversion mode, and generating the target JSON data according to the multiple field mapping rules in the direct mapping conversion mode. Complex structure conversion and logic processing can be defined through the simple JSON conversion configuration file, and low-code and high-efficiency data integration is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, specifically to a JSON data conversion method, apparatus, medium, electronic device, and computer program product. Background Technology

[0002] With the rapid development of microservice architecture, mobile internet, and IoT technologies, JSON (JavaScript Object Notation) has become the de facto standard format for data exchange between heterogeneous systems. In actual software development and system integration, due to the differences in data structure definitions among different business systems (such as front-end applications, back-end services, third-party APIs, and legacy systems), it is often necessary to clean, reorganize, map, and convert the transmitted JSON data.

[0003] Traditional conversion methods typically employ hard coding, object mapping frameworks, or dedicated JSON conversion libraries (such as Joit), but these methods suffer from poor flexibility, low performance, and difficulty in maintenance. Summary of the Invention

[0004] The technical problem to be solved by this invention is to address the above-mentioned shortcomings by proposing a JSON data conversion method based on configuration and expression engine. Complex structural conversions and logical processing can be defined through a simple JSON conversion configuration file, and performance issues are solved by using pre-compilation technology, thereby achieving low-code and high-efficiency data integration.

[0005] This application provides JSON data conversion methods, JSON data conversion devices, media, electronic devices, and computer program products.

[0006] In a first aspect, embodiments of this application provide a JSON data conversion method for electronic devices, comprising:

[0007] The configuration file receiving step involves receiving a transformation configuration file, which contains a list of field mapping rules. Each field mapping rule in the list defines a source path, a transformation expression, and a target path.

[0008] The pre-compilation step parses the source path and the target path in each field mapping rule to obtain the parsed source path and the parsed target path, and compiles the transformation expression to generate a reusable script instance;

[0009] The data receiving step involves receiving source JSON data to be converted, wherein the source JSON data includes multiple fields, and determining multiple field mapping rules that correspond one-to-one with each of the multiple fields from the field mapping rule list;

[0010] The mode determination step involves determining the conversion mode based on whether a final result template is defined in the conversion configuration file. If the final result template exists, the conversion mode is entered into the template-driven conversion mode; otherwise, the conversion mode is entered into the direct mapping conversion mode.

[0011] In the transformation step, under the template-driven transformation mode, target JSON data is generated from the source JSON data according to the template mapping rules and the multiple field mapping rules in the final result template.

[0012] In the direct mapping conversion mode, the target JSON data is generated from the source JSON data according to the multiple field mapping rules.

[0013] Secondly, embodiments of this application provide a JSON data conversion apparatus, including:

[0014] The configuration file receiving unit receives a transformation configuration file, which contains a list of field mapping rules. Each field mapping rule in the list defines a source path, a transformation expression, and a target path.

[0015] The pre-compilation unit parses the source path and the target path in each field mapping rule to obtain the parsed source path and the parsed target path, and compiles the transformation expression to generate a reusable script instance;

[0016] The data receiving unit receives source JSON data to be converted, the source JSON data including multiple fields, and determines multiple field mapping rules from the field mapping rule list that correspond one-to-one with each of the multiple fields;

[0017] The mode determination unit determines the conversion mode based on whether a final result template is defined in the conversion configuration file. If the final result template exists, the conversion mode is entered into the template-driven conversion mode; otherwise, the conversion mode is entered into the direct mapping conversion mode.

[0018] In the template-driven conversion mode, the conversion unit generates target JSON data from the source JSON data according to the template mapping rules and the multiple field mapping rules in the final result template.

[0019] In the direct mapping conversion mode, the target JSON data is generated from the source JSON data according to the multiple field mapping rules.

[0020] Thirdly, embodiments of this application provide a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the JSON data conversion method described in the first aspect above.

[0021] Fourthly, embodiments of this application provide an electronic device, including: one or more processors; one or more memories; the one or more memories storing one or more programs, which, when executed by the one or more processors, cause the electronic device to perform the JSON data conversion method described in the first aspect above.

[0022] Fifthly, embodiments of this application provide a computer program product including computer-executable instructions that are executed by a processor to implement the JSON data conversion method of the first aspect.

[0023] This invention shifts runtime overhead to the initialization phase through pre-compilation optimization, avoiding repeated parsing and compilation during each data conversion and significantly improving conversion performance. By introducing a dual-mode conversion mechanism of template-driven and direct mapping (two complementary conversion modes), the solution can flexibly handle various business scenarios, from simple field mapping to complex template filling, improving its versatility and applicability. Configurable conversion logic decouples business rules from the execution engine, greatly enhancing system maintainability and scalability. Furthermore, intelligent processing of array structures and the design of mixed expressions (supporting scripts and high-performance instructions) further enhance the solution's ability to handle complex data structures and balance flexibility and performance.

[0024] This invention supports mixed expressions. In the transformation expression of the mapping rule, it supports directly embedding JSONPath (such as $.field) to reference source data, while also supporting logical operations (such as ternary operators and string processing) using Groovy syntax, and supporting the execution of dynamic logic during the transformation process.

[0025] This invention provides intelligent pre-compilation, which parses and pre-compiles all JSONPath paths (source path and target path) and Groovy expressions (transformation expressions) during the initialization phase, and then caches them. For complex expressions containing JSONPath, a "placeholder replacement" technique is used to convert dynamic paths into static variables for pre-compilation, and values ​​are dynamically injected during execution, greatly improving conversion performance. Attached Figure Description

[0026] Figure 1 According to an embodiment of this application, a flowchart of a JSON data conversion method is shown;

[0027] Figure 2 According to an embodiment of this application, an exemplary schematic diagram of template mapping rules in the final result template is shown;

[0028] Figure 3 According to embodiments of this application, an exemplary schematic diagram of multiple field mapping rules is shown;

[0029] Figure 4 According to embodiments of this application, an exemplary schematic diagram of a target JSON object is shown.

[0030] Figure 5 According to an embodiment of this application, a structural diagram of a JSON data conversion apparatus is shown;

[0031] Figure 6 According to an embodiment of this application, a block diagram of an electronic device is shown. Detailed Implementation

[0032] The illustrative embodiments of this application include, but are not limited to, JSON data conversion methods, JSON data conversion apparatuses, media, electronic devices, and computer program products.

[0033] The embodiments of this application will now be described in further detail with reference to the accompanying drawings.

[0034] Figure 1 A flowchart illustrating a JSON data conversion method according to an embodiment of this application is shown, for use in... Figure 6 The electronic device shown.

[0035] In the configuration file receiving step S11, a transformation configuration file is received. The transformation configuration file contains a list of field mapping rules. Each field mapping rule in the list of field mapping rules defines a source path, a transformation expression, and a target path.

[0036] Understandably, the source path defines which path the data is retrieved from in the source JSON, the transformation expression defines the logical processing of the retrieved data, and the target path defines which path the data is ultimately written to in the target JSON.

[0037] In the pre-compilation step S12, the source path and target path in each field mapping rule are parsed to obtain the parsed source path and parsed target path. The transformation expression is then compiled to generate a reusable script instance. It is understood that the parsed source path, parsed target path, and script instance are cached for later use.

[0038] In JSON data conversion, path parsing refers to converting the path string (such as the JSONPath expression) defined in the configuration file into an internal data structure that can quickly locate the specific value in the JSON data. This allows the specific value in the source JSON data to be directly located and extracted during subsequent conversions without having to repeatedly parse the path string, thus improving performance.

[0039] Furthermore, compiling the transformation expression specifically includes:

[0040] Check if the conversion expression contains a JSONPath reference;

[0041] If it is included, then for example, the JSONPath reference is extracted by regular expression matching and replaced with standard variable placeholders, thereby generating a standard script string;

[0042] For example, it can call a script engine to compile standard script strings and generate script instances.

[0043] In the data receiving step S13, the source JSON data to be converted is received. The source JSON data includes multiple fields. Multiple field mapping rules corresponding to each of the multiple fields are determined from the field mapping rule list.

[0044] Each field in the source JSON data includes the source path. Based on the source path of each field, multiple field mapping rules are determined from the list of field mapping rules, each corresponding to one of the multiple fields.

[0045] For example, the source JSON data includes fields A and B, where field A includes the source path `sourcePathA` and field B includes the source path `sourcePathB`. Find the field mapping rule `RA` for source path `sourcePathA` and the field mapping rule `RB` for source path `sourcePathB` from the list of field mapping rules.

[0046] In the mode determination step S14, the conversion mode is determined based on whether a final result template is defined in the conversion configuration file. If a final result template (finalJsonTemplate) exists, the conversion mode is entered into the template-driven conversion mode; otherwise, the conversion mode is entered into the direct mapping conversion mode.

[0047] Template-driven transformation mode is suitable for scenarios where the target JSON data structure is complex and contains a large number of fixed fields, while this direct mapping transformation mode is suitable for scenarios where the source JSON data and the target JSON data structure are not significantly different, or where only simple reorganization is needed.

[0048] The two modes will be explained in detail below.

[0049] 1) Template-driven conversion mode

[0050] If a final result template is defined in the conversion configuration file, then the template-driven conversion mode is entered. In conversion step S15, target JSON data is generated from the source JSON data according to the template mapping rules and multiple field mapping rules in the final result template.

[0051] Specifically, first, the final result template T is loaded as the base of the final result object. Then, template mapping is executed, that is, multiple fixed fields (also called default fields) in the final result template T are populated according to template mapping rules. These template mapping rules are used to generate values ​​for multiple fixed fields that are independent of the source JSON data; the values ​​of these fixed fields are dynamically invoked values ​​or default values.

[0052] Figure 2 An exemplary schematic diagram of template mapping rules in the final result template T according to an embodiment of the present invention is shown.

[0053] like Figure 2 As shown, "transformExpression": "@time:current" means that the current time is used as the value of this fixed field, that is, the value is dynamically called.

[0054] The rule “TransformExpression”: “10000” means that the value of this fixed field is a fixed number 10000, that is, the default value.

[0055] It is understandable that the fields in template T do not have sourcePath, because the population of the fields in template T does not depend on the source JSON data.

[0056] Next, the field mapping method is executed. That is, based on multiple field mapping rules, multiple fields of the source JSON data are transformed to generate the target JSON object. The populated fixed fields and the target JSON object together form the target JSON data. The specific process will be described below.

[0057] Understandably, in template-driven conversion mode, both the template mapping method and the field mapping method described above are executed.

[0058] 2) Direct mapping conversion mode

[0059] If the final result template is not defined in the conversion configuration file, then the direct mapping conversion mode is entered. In conversion step S15, the field mapping method is executed, that is, according to multiple field mapping rules, multiple fields of the source JSON data are converted to generate the target JSON object as the target JSON data.

[0060] Understandably, in direct mapping conversion mode, only the above field mapping method needs to be executed.

[0061] The field mapping method is described in detail below.

[0062] In this embodiment, for example, field mapping rules RA and RB are determined for fields A and B of the source JSON data as described above. The transformation of fields A and B according to field mapping rules RA and RB includes: traversing field mapping rules RA and RB; for each field mapping rule, extracting data values ​​from the source JSON data using the parsed source path; performing logical operations defined by the transformation expression on the data values ​​using a pre-compiled script instance; and writing the result to the location specified by the parsed target path of the target JSON object.

[0063] Figure 3 An exemplary schematic diagram of multiple field mapping rules according to an embodiment of the present invention is shown. Traversing to, for example, field mapping rule RA, such as... Figure 3 As can be seen, the parsed source path of field A is, for example, the field "ip_location", from which the data value corresponding to "ip_location" is extracted. Then, the pre-compiled script instance "transformExpression" is used to perform logical operations on the data value to obtain the result.

[0064] Here, the pre-compiled script instance refers to the script instance of the pre-compiled transformation expression mentioned above (e.g., a Groovy expression). It's understandable that some Groovy expressions require source JSON data for calculation, while others can be obtained directly without it. For example, after extracting the data value `userID`, the Groovy expression needs to perform calculations based on `userID` (e.g., +1) to obtain a dynamic value. Furthermore, some Groovy expressions retrieve / retrieve the current timestamp.

[0065] Write the result of the operation to the location specified in the target path after parsing the target JSON object (targetJson). Figure 4 An exemplary schematic diagram of a target JSON object according to an embodiment of the present invention is shown. Figure 4 As shown, "mappings" represents the field mapping rules, and "$.post_uuid" represents the target path after parsing. The calculation result will be written to the location specified by "$.post_uuid" in the target JSON object (targetJson).

[0066] Preferably, each field mapping rule also includes a target data type (targetType). Before writing the calculation result, the result is converted to the corresponding data type based on the target data type (targetType). For example, targetType can be defined as String, Integer, Long, Double, Boolean, etc. In this way, regardless of the data type of the calculation result (i.e., regardless of the data type of the source JSON data), it can be directly converted to the expected target data type.

[0067] Following a similar approach, field B is transformed according to the field mapping rule RB. This converts the source JSON data into a target JSON object (targetJson).

[0068] Understandably, in template-driven transformation mode, the multiple fixed fields populated as described above and the transformed (generated) target JSON object (targetJson) form the final target JSON data. In direct mapping transformation mode, the transformed (generated) target JSON object (targetJson) as described above forms the final target JSON data.

[0069] Understandably, the conversion configuration file contains an initialized target JSON object (TargetJson) (also known as the target object skeleton). By performing logical operations on the source JSON data as described above and writing it to the location specified in the target path after parsing the target JSON object, the final target JSON object is generated.

[0070] Understandably, in direct mapping conversion mode, if the initialization target JSON object (TargetJson) is not configured in the conversion configuration file, an empty target object is created, and then the field mapping rules are applied directly to the empty target object. The missing nested hierarchical structure (ObjectNode or ArrayNode) is automatically created and its value is set according to the target path.

[0071] Understandably, when the data value extracted from the source path is an array, the field mapping rules are applied independently to each element object in the array to generate a transformed sub-object, and all the transformed sub-objects are aggregated into a list and assigned to the location specified in the parsed target path.

[0072] It is understood that the method of this invention supports mixed expression processing. Specifically, the transformation expression supports embedding scripting languages ​​(such as Groovy) for logical judgment, string processing, and mathematical operations; it also supports custom special instructions (such as the @time: prefix instruction) for quickly processing time formatting and timestamp generation without calling the script engine.

[0073] This invention shifts runtime overhead to the initialization phase through pre-compilation optimization, avoiding repeated parsing and compilation during each data conversion and significantly improving conversion performance. By introducing a dual-mode conversion mechanism of template-driven and direct mapping (two complementary conversion modes), the solution can flexibly handle various business scenarios, from simple field mapping to complex template filling, improving its versatility and applicability. Configurable conversion logic decouples business rules from the execution engine, greatly enhancing system maintainability and scalability. Furthermore, intelligent processing of array structures and the design of mixed expressions (supporting scripts and high-performance instructions) further enhance the solution's ability to handle complex data structures and balance flexibility and performance.

[0074] This invention supports mixed expressions. In the transformation expression of the mapping rule, it supports directly embedding JSONPath (such as $.field) to reference source data, while also supporting logical operations (such as ternary operators and string processing) using Groovy syntax, and supporting the execution of dynamic logic during the transformation process.

[0075] This invention provides intelligent pre-compilation, which parses and pre-compiles all JSONPath paths and Groovy expressions during the initialization phase and caches them. For complex expressions containing JSONPath, a "placeholder replacement" technique is used to convert dynamic paths into static variables for pre-compilation, and values ​​are dynamically injected during execution, greatly improving conversion performance.

[0076] This invention provides a JSON data conversion device, such as... Figure 5 As shown, the device 50 includes:

[0077] The configuration file receiving unit 501 receives a conversion configuration file, which contains a list of field mapping rules. Each field mapping rule in the list defines a source path, a conversion expression, and a target path.

[0078] The pre-compilation unit 502 parses the source path and the target path in each field mapping rule to obtain the parsed source path and the parsed target path, and compiles the transformation expression to generate a reusable script instance.

[0079] The data receiving unit 503 receives source JSON data to be converted, the source JSON data including multiple fields, and determines multiple field mapping rules that correspond one-to-one with the multiple fields from the field mapping rule list;

[0080] The mode determination unit 504 determines the conversion mode based on whether a final result template is defined in the conversion configuration file. If the final result template exists, the conversion mode is entered into the template-driven conversion mode; otherwise, the conversion mode is entered into the direct mapping conversion mode.

[0081] In the template-driven conversion mode, conversion unit 505 generates target JSON data from the source JSON data according to the template mapping rules and the multiple field mapping rules in the final result template.

[0082] In the direct mapping conversion mode, the target JSON data is generated from the source JSON data according to the multiple field mapping rules.

[0083] It is understandable that the configuration file receiving unit 501, the pre-compilation unit 502, the data receiving unit 503, the mode determination unit 504, and the conversion unit 505 can be... Figure 6 The processor 1404 in the electronic device 1400 has the functions of these modules or units to implement them.

[0084] The present invention also provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform [operations]. Figure 1 The method shown.

[0085] The present invention also provides a computer program product, including computer-executable instructions, which are executed by processor 1404 to perform [the following]. Figure 1 The method shown.

[0086] Now for reference Figure 6 , Figure 6 An example electronic device 1400 according to an embodiment of the present invention is illustrated schematically. In one embodiment, the electronic device 1400 may include one or more processors 1404, a system control logic unit 1408 connected to at least one of the processors 1404, a system memory 1412 connected to the system control logic unit 1408, a non-volatile memory (NVM) 1416 connected to the system control logic unit 1408, and a network interface 1420 connected to the system control logic unit 1408.

[0087] In some embodiments, processor 1404 may include one or more single-core or multi-core processors. In some embodiments, processor 1404 may include any combination of general-purpose processors and special-purpose processors (e.g., graphics processors, application processors, baseband processors, etc.). In embodiments where electronic device 1400 employs an eNB (Evolved Node B) or RAN (Radio Access Network) controller, processor 1404 may be configured to perform various conforming embodiments, such as... Figure 1 The example shown.

[0088] In some embodiments, the system control logic unit 1408 may include any suitable interface controller to provide any suitable interface to at least one of the processors 1404 and / or any suitable device or component communicating with the system control logic unit 1408.

[0089] In some embodiments, the system control logic unit 1408 may include one or more memory controllers to provide an interface to the system memory 1412. The system memory 1412 may be used to load and store data and / or instructions. In some embodiments, the system memory 1412 of the electronic device 1400 may include any suitable volatile memory, such as suitable dynamic random access memory (DRAM).

[0090] The non-volatile memory 1416 may include one or more tangible, non-transitory computer-readable media for storing data and / or instructions. In some embodiments, the non-volatile memory 1416 may include any suitable non-volatile memory such as flash memory and / or any suitable non-volatile storage device, such as at least one of HDD (Hard Disk Drive), CD (Compact Disc) drive, and DVD (Digital Versatile Disc) drive.

[0091] The non-volatile memory 1416 may include a portion of the storage resources on the device on which the electronic device 1400 is installed, or it may be accessible by the electronic device, but is not necessarily part of the electronic device. For example, the non-volatile memory 1416 may be accessed over a network via network interface 1420.

[0092] Specifically, system memory 1412 and non-volatile memory 1416 may each include a temporary copy and a permanent copy of instruction 1424. Instruction 1424 may include, when executed by at least one of processors 1404, causing electronic device 1400 to perform, as Figure 1The instructions for the method shown. In some embodiments, the instructions 1424, hardware, firmware and / or software components thereof may additionally / alternatively be located in the system control logic unit 1408, the network interface 1420 and / or the processor 1404.

[0093] Network interface 1420 may include a transceiver for providing a radio interface to electronic device 1400, thereby enabling communication with any other suitable device (such as a front-end module, antenna, etc.) via one or more networks. In some embodiments, network interface 1420 may be integrated into other components of electronic device 1400. For example, network interface 1420 may be integrated into at least one of processor 1404, system memory 1412, non-volatile memory 1416, and firmware device (not shown) with instructions, which, when at least one of processor 1404 executes the instructions, enable electronic device 1400 to perform as follows: Figure 1 The method shown.

[0094] The network interface 1420 may further include any suitable hardware and / or firmware to provide a multiple-input multiple-output radio interface. For example, the network interface 1420 may be a network adapter, a wireless network adapter, a telephone modem, and / or a wireless modem.

[0095] In one embodiment, at least one of the processors 1404 may be packaged together with the logic of one or more controllers for the system control logic unit 1408 to form a system package (SiP). In another embodiment, at least one of the processors 1404 may be integrated on the same die with the logic of one or more controllers for the system control logic unit 1408 to form a system on chip (SoC).

[0096] The electronic device 1400 may further include an input / output (I / O) device 1432. The I / O device 1432 may include a user interface enabling a user to interact with the electronic device 1400; the peripheral component interface is designed to allow peripheral components to also interact with the electronic device 1400. In some embodiments, the electronic device 1400 may also include sensors for determining at least one of environmental conditions and location information related to the electronic device 1400.

[0097] In some embodiments, the user interface may include, but is not limited to, a display (e.g., a liquid crystal display, a touch screen display, etc.), a speaker, a microphone, one or more cameras (e.g., a still image camera and / or a video camera), a flashlight (e.g., a light-emitting diode flash), and a keyboard.

[0098] Various embodiments of the mechanisms disclosed in this application can be implemented in hardware, software, firmware, or combinations of these implementation methods. Embodiments of this application can be implemented as computer programs or program code executable on a programmable system, the programmable system including at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device.

[0099] Program code can be applied to input instructions to execute the functions described in this application and generate output information. The output information can be applied to one or more output devices in a known manner. For the purposes of this application, the processing system includes any system having a processor such as, for example, a digital signal processor (DSP), a microcontroller, an application-specific integrated circuit (ASIC), or a microprocessor.

[0100] The program code can be implemented using a high-level procedural language or an object-oriented programming language to communicate with the processing system. Assembly language or machine language can also be used when needed. In fact, the mechanisms described in this application are not limited to any particular programming language. In either case, the language can be a compiled language or an interpreted language.

[0101] In some cases, the disclosed embodiments may be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments may also be implemented as instructions carried or stored thereon on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which may be read and executed by one or more processors. For example, the instructions may be distributed via a network or through other computer-readable media. Therefore, machine-readable media may include any mechanism for storing or transmitting information in a machine-readable (e.g., computer-readable) form, including but not limited to floppy disks, optical disks, CD-ROMs, magneto-optical disks, read-only memory (CD-ROM), random access memory (RAM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), magnetic cards or optical cards, flash memory, or tangible machine-readable storage for transmitting information (e.g., carrier waves, infrared signals, digital signals, etc.) using the Internet in the form of electrical, optical, acoustic, or other propagation signals. Therefore, machine-readable media include any type of machine-readable medium suitable for storing or transmitting electronic instructions or information in a machine-readable (e.g., computer-readable) form.

[0102] In the accompanying drawings, some structural or methodological features may be shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be necessary. Rather, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. Furthermore, the inclusion of structural or methodological features in a particular figure does not imply that such features are required in all embodiments, and in some embodiments, these features may be omitted or may be combined with other features.

[0103] It should be noted that all units / modules mentioned in the device embodiments of this application are logical units / modules. Physically, a logical unit / module can be a physical unit / module, a part of a physical unit / module, or a combination of multiple physical units / modules. The physical implementation of these logical units / modules themselves is not the most important factor; the combination of functions implemented by these logical units / modules is the key to solving the technical problems proposed in this application. Furthermore, to highlight the innovative aspects of this application, the above-described device embodiments of this application have not introduced units / modules that are not closely related to solving the technical problems proposed in this application. This does not mean that the above-described device embodiments do not contain other units / modules.

[0104] It should be noted that in the examples and description of this patent, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one" does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0105] Although this application has been illustrated and described with reference to certain preferred embodiments thereof, those skilled in the art should understand that various changes in form and detail may be made thereto without departing from the spirit and scope of this application.

Claims

1. A JSON data conversion method for electronic devices, characterized in that, include: The configuration file receiving step involves receiving a transformation configuration file, which contains a list of field mapping rules. Each field mapping rule in the list defines a source path, a transformation expression, and a target path. The pre-compilation step parses the source path and the target path in each field mapping rule to obtain the parsed source path and the parsed target path, and compiles the transformation expression to generate a reusable script instance; The data receiving step involves receiving source JSON data to be converted, wherein the source JSON data includes multiple fields, and determining multiple field mapping rules that correspond one-to-one with each of the multiple fields from the field mapping rule list; The mode determination step involves determining the conversion mode based on whether a final result template is defined in the conversion configuration file. If the final result template exists, the conversion mode is entered into the template-driven conversion mode; otherwise, the conversion mode is entered into the direct mapping conversion mode. In the transformation step, under the template-driven transformation mode, target JSON data is generated from the source JSON data according to the template mapping rules and the multiple field mapping rules in the final result template. In the direct mapping conversion mode, the target JSON data is generated from the source JSON data according to the multiple field mapping rules.

2. The JSON data conversion method according to claim 1, characterized in that, In the template-driven transformation mode, multiple fixed fields in the final result template are populated according to the template mapping rules, and the multiple fields of the source JSON data are transformed according to the multiple field mapping rules to generate the target JSON object. The populated fixed fields and the target JSON object together form the target JSON data. In the direct mapping conversion mode, the multiple fields of the source JSON data are converted according to the multiple field mapping rules to generate the target JSON object, which serves as the target JSON data.

3. The JSON data conversion method according to claim 2, characterized in that, Based on the aforementioned multiple field mapping rules, the multiple fields of the source JSON data are transformed, including: The system iterates through the multiple field mapping rules. For each field mapping rule, it extracts data values ​​from the source JSON data using the parsed source path, performs logical operations defined by the transformation expression on the data values ​​using the pre-compiled script instance, and writes the operation result to the location specified by the parsed target path of the target JSON object.

4. The JSON data conversion method according to claim 3, characterized in that, Each field mapping rule also includes the target data type. Before writing the calculation result, the calculation result is converted into the corresponding data type according to the target data type in the field mapping rule.

5. The JSON data conversion method according to claim 1, characterized in that, Each field in the source JSON data includes a source path. Based on the source path of each field, multiple field mapping rules corresponding to each of the multiple fields are determined from the field mapping rule list.

6. The JSON data conversion method according to claim 1, characterized in that, The pre-compilation step, which involves compiling the transformation expression, includes: Detect whether the conversion expression contains a JSONPath reference; If it is included, the JSONPath reference is extracted and replaced with a standard variable placeholder to generate a standard script string; The standard script string is compiled to generate the script instance.

7. The method according to claim 1, characterized in that, In the template-driven conversion mode, the template mapping rules are used to generate values ​​for multiple fixed fields that are independent of the source JSON data. The values ​​of these multiple fixed fields are dynamically invoked values ​​or default values.

8. The method according to claim 3, characterized in that, The method further includes: When the data value extracted from the source path is an array, the field mapping rule is applied independently to each element object in the array to generate a transformed sub-object. All transformed sub-objects are then aggregated into a list and assigned to the position specified by the parsed target path.

9. A JSON data conversion device, characterized in that, include: The configuration file receiving unit receives a transformation configuration file, which contains a list of field mapping rules. Each field mapping rule in the list defines a source path, a transformation expression, and a target path. The pre-compilation unit parses the source path and the target path in each field mapping rule to obtain the parsed source path and the parsed target path, and compiles the transformation expression to generate a reusable script instance; The data receiving unit receives source JSON data to be converted, the source JSON data including multiple fields, and determines multiple field mapping rules from the field mapping rule list that correspond one-to-one with each of the multiple fields; The mode determination unit determines the conversion mode based on whether a final result template is defined in the conversion configuration file. If the final result template exists, the conversion mode is entered into the template-driven conversion mode; otherwise, the conversion mode is entered into the direct mapping conversion mode. In the template-driven conversion mode, the conversion unit generates target JSON data from the source JSON data according to the template mapping rules and the multiple field mapping rules in the final result template. In the direct mapping conversion mode, the target JSON data is generated from the source JSON data according to the multiple field mapping rules.

10. A computer-readable storage medium, characterized in that, The storage medium stores instructions that, when executed on a computer, cause the computer to perform the JSON data conversion method according to any one of claims 1-8.

11. An electronic device, characterized in that, include: One or more processors; One or more memories; the one or more memories storing one or more programs, which, when executed by the one or more processors, cause the electronic device to perform the JSON data conversion method according to any one of claims 1-8.

12. A computer program product comprising computer-executable instructions, characterized in that, The instructions are executed by the processor to implement the JSON data conversion method according to any one of claims 1-8.