You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1.0 KiB
26 lines
1.0 KiB
⟨NQ,NQS,Split,ES,SS⟩ ← •Import "helpers.bqn" |
|
|
|
# comment this and figure it out |
|
#NQ ←{0=2|+`('"'=𝕩)∧ ¬e∧¬(¯1⌽0∾"\\"⍷𝕩)∧e←0∾"\"""⍷𝕩} |
|
|
|
StripWS←{ |
|
ws ←' '∾(@+9‿10‿13) |
|
E ← NQ∧∊⟜ws |
|
(¬∘E⊸/)𝕩 |
|
} |
|
|
|
JSON⇐{J string: |
|
s ←StripWS string |
|
Beg← NQ∧∊⟜"{[" # opening brackets |
|
End← NQ∧∊⟜"}]" # closing brackets |
|
n ←+`(Beg - End)s # levels of [n]esting |
|
g ← (+`(1⊸»≠⊢)n)⊔s # [g]roup by nesting |
|
d ← 1∾(1⊸»≠⊢)⊸/n # [d]epth for each [g]roup |
|
PK ← ¬∘∊⟜"""{}[]()"⊸/ # remove quotes and brackets |
|
PV ←{1↓¯1↓𝕩} # remove first lead/trail quote |
|
KV ←{(⊑𝕩⊐':')(↑≍○<1⊸+⊸↓)𝕩} # [k]ey [v]al pairs, split on first ':' |
|
|
|
Parse←{PK‿PV{𝕎 𝕩}¨2↑(KV𝕩)∾<""} # ! 2=≠result , parsed keys and vals |
|
fmt←∾´d{𝕨∾˘ >Parse¨','NQS 𝕩}¨g # format: 3 col mat, [d]epth key val |
|
((<"")≢¨1⊏˘fmt)/fmt |
|
}
|
|
|