Convert a field that is XML to an object #2705
rhscjohn-dev
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have an old SQlite db whose tables have fields that contain XML. An example of one such field in the table: CHANNEL.
"epgMapping" varchar(50) NOT NULL
Here is an example of a row fetched by an SQlite query,
In Zod the initial declaration for the column: epgMapping would be
epgMapping: z.string()
I wanted to convert this XML column/field to an object before passing it onto the client. I want to use Zod's preprocess(). I decided to use the npm package: fast-xml-parser for parsing xml to an object.
Here are the the zod schemas for an individual record and for an array of records.
Javascript code to parse an individual record and an array of records.
The console. log for an individual record.
Beta Was this translation helpful? Give feedback.
All reactions