Created
March 9, 2026 20:45
-
-
Save gbluv/e26cb55fbb7fb517162f10d31a66109a to your computer and use it in GitHub Desktop.
json_store_parser.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require("fs") | |
| // load rules file | |
| const rules = JSON.parse(fs.readFileSync("rules.json", "utf8")) | |
| const rows = [] | |
| for (const rule of rules) { | |
| let parsed | |
| try { | |
| parsed = JSON.parse(rule.json_data) | |
| } catch { | |
| continue | |
| } | |
| const groups = parsed.conditionGroups || [] | |
| for (const group of groups) { | |
| const conditions = group.conditions || [] | |
| for (const cond of conditions) { | |
| const values = cond.values || [] | |
| for (const v of values) { | |
| rows.push([ | |
| rule.user_id, | |
| rule.rule_category_name, | |
| cond.fieldName, | |
| cond.operator, | |
| v.value1 ?? "", | |
| v.value2 ?? "" | |
| ]) | |
| } | |
| } | |
| } | |
| } | |
| // CSV header | |
| const header = [ | |
| "user_id", | |
| "rule_category_name", | |
| "field_name", | |
| "operator", | |
| "value1", | |
| "value2" | |
| ] | |
| // create csv | |
| const csv = [header.join(","), ...rows.map(r => r.join(","))].join("\n") | |
| fs.writeFileSync("output.csv", csv) | |
| console.log(`Exported ${rows.length} rows to output.csv`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment