DEV Community

Judy
Judy

Posted on

2 1 1 1 1

How to Convert JSON Data into a Two-dimensional Table and Export It to a CSV #78

Problem description & analysis

Below is data in JSON file json.json:
Image description
To convert the multilevel JSON file into a two-dimensional structure while splitting the two subfields under identities field and promoting them to the parent level, and store data as a CSV file as follows:

Image description
Solution:
We write the following script p1.dfx in esProc:

Image description
Code description:

A1   Read data of the JSON file as a string.
A2  Parse the string into a multilevel table sequence according to the original structure while splitting and promoting identities.signInType and identities.issuerAssignedId to their parent level with the new function.
A3  Export A2’s result to json.csv.

See How to Call an SPL Script in Java to learn about the way of integrating the SPL code with a Java program.

Open source SPL source address

Download

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay