Skip to the content
PCBKitNew board
4 layers16 × 13 mmBoard2, the printed circuit board in 3D

A PegJS parser for Kicad Modules

Size
16 × 13 mm
Copper layers
4
Thickness
1.6 mm
Parts
2
Nets
2
Pads
4
Tracks, vias
5, 0
Pours
1
Routed
Yes
KiCad
KiCad 3
Created
9 Aug 2020
Updated
17 Nov 2024

Overview

Board2 is an open-source printed circuit board by jdthorpe, from the jdthorpe/kicad-module-parser repository on GitHub. It is a 4-layer board of 16 × 13 mm with 2 parts on 2 nets, routed with 5 tracks and 0 vias.

Its parts include 1 capacitor and 1 resistor.

README

README.md

Convert Kicad Board and Module files to JSON

Do you love working with S-Expressions? Me either. Convert your Kicad board and module files to JSON or YAML and use your favorite tools to work with your Kicad board and module file data!

CLI Usage

When installed globally (npm i -g kicad-to-json), npm installs the k2j command line tool, which converts your kicad files to json like so:

sh
k2j ./my_module_file.kicad_mod
# creates ./my_module_file.json in compact format

k2j ./my_board_file.kicad_pcb --yaml --format long
# creates ./my_board_file.yaml in long format

Use the -h flag for the usual help:

txt
usage: index.js [-h] [-o OUTPUT] [-f {compact,long,bare}] [-v] [--yaml] file

Convert Kicad board and module files to JSON/YAML

positional arguments:
  file                  The Kicad pcb or module file to convert to json

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        Output file (defaults to input file with '.json' or '.yaml' extension)
  -f {compact,long,bare}, --format {compact,long,bare}
                        Set the output format
  -v, --verbose         verbose output
  --yaml                set output to yaml

Javascript / Typescript Usage

User friendly data

ts
import { parse } from "kicad-module-parser"

// convert the module (string) to compact format
const my_module = parse.module(kicad_mod_contents_string)

// convert the board (string) to long format
const my_board = parse.board(kicad_pcb_contents_string,"long")

Output Formats

Background

The kicad_mod and kicad_pcb files are S-Expressions based which have the general format (name ...contents ) where the contents are either individual values or nested s-expressions (e.g. ( pts (xy 1 1) (xy 2 2))). Some s-expressions are singletons, such as the pts expression within a polygon and others can appear multiple times, such as the individual xy pairs within an array of points.

bare Notation

In the bare notation the first token in the s-expresion appears as it's type attribute, and the remaining sub-expression appear in the value attribute. This format is quite literal, but generally hard to work with. Here is a brief example (in yaml format):

yaml
type: kicad_pcb
value:
  - type: version
    value:
      type: number
      value: '20171130'
  - type: general
    value:
      - type: thickness
        value:
          type: number
          value: '1.6'
      - type: drawings
        value:
          type: number
          value: '605'
      - type: tracks
        value:
          type: number
          value: '2555'
      - type: zones
        value:
          type: number
          value: '0'

compact Notation

In the compact format, s-expression types and values from the bare format are used as key-value pairs of a JSON object This works for s-expressions that are singletons, but for expressions like (add_net GND) (add_net +3v3) which may appear multiple times within the parent s-expression, the contents of the expression are included in an array of the same name, such as :

json
{
    "add_net":[
        {"net_name": "GND"},
        {"net_name": "+3v3"}
    ]
}

Here is the same example from above in compact format:

yaml
kicad_pcb:
  version: 20171130
  general:
    thickness: 1.6
    drawings: 605
    tracks: 2555
    zones: 0
    modules: 172
    nets: 143

long Notation

The long format is a hybrid between the Compact and Bare formats, and recoginses that module and board files are special, in that nearly every file will have many repeating entities (such as gr_lines) where preserving the order of the entites may be useful. Hence, the immediate children of boards and modules (and modules nested within boards) are represent in bare format, and everything else is represented in compact format. Here is the same example from above in long format:

yaml
kicad_pcb:
  - type: version
    value: 20171130
  - type: general
    value:
      thickness: 1.6
      drawings: 605
      tracks: 2555
      zones: 0
      modules: 172
      nets: 143

bare Format Details

There are 4 primitives in the bare format which have type "string", "hex", "number" and "boolean", such as:

json
{ "type": "string", "value": "GND" }
{ "type": "hex", "value": "1234ABCD" }
{ "type": "number", "value": "3.2" } // yes, numbers are represented as strings
{ "type": "boolean", "value": true }

The array type has a type attribute of "array" and a value contianing an aray of primitives, such as:

json
{ "type": "array", "value": [ { "type": "string", "value": "GND" } ] }

The container type is like the array type but it's type attribute has a value other than "string", "hex", "number", "boolean" or "array", and the value can contain any type (including other containers), or an array containing any of the types, sucy as:

json
{
  "type": "xy",
  "value": [
    {
      "type": "x",
      "value": {
        "type": "number",
        "value": "117.4"
      }
    },
    {
      "type": "y",
      "value": {
        "type": "number",
        "value": "28"
      }
    }
  ]
}

Final notes

There are a handfule of sub-parsers and things I was not personally interested in (such as page formatting) which result in a value like "page info": "unsupported". If you despirately need page info (or any other unsupported features), I welcome your pull request!

If your board or module results in an error, please put it in a github repo (or a minimal example that raises the same error), and open an issue with a link to that github repo.

Parts

2
QtyValueFootprintReferences
110uFCP4C1
1330KR3R1

Questions

How big is the Board2 PCB?

It measures 16 × 13 mm and has 4 copper layers, 1.6 mm thick.

What parts does the Board2 use?

2 parts. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the Board2 KiCad files?

From the jdthorpe/kicad-module-parser repository on GitHub, at the commit this page was made from: the board is data/pcb/custom/Board2.kicad_pcb. PCBKit opens the board in the browser, with nothing to install.

Can I use the Board2 design in my own project?

Its repository states no licence, so its author keeps all rights: ask jdthorpe before reusing the design.

More from jdthorpe/kicad-module-parser

4
  • 4 layers85 × 57.5 mmFirefly, the printed circuit board in 3D

    Firefly

    jdthorpe/kicad-module-parser

    A PegJS parser for Kicad Modules

    104 parts12
  • 4 layers43 × 24 mmDisco, the printed circuit board in 3D

    Disco

    jdthorpe/kicad-module-parser

    A PegJS parser for Kicad Modules

    21 parts12
  • 2 layers18 × 20 mmUsbPower, the printed circuit board in 3D

    UsbPower

    jdthorpe/kicad-module-parser

    A PegJS parser for Kicad Modules

    6 parts12
  • 4 layers16 × 13 mmBoard simple, the printed circuit board in 3D

    Board simple

    jdthorpe/kicad-module-parser

    A PegJS parser for Kicad Modules

    2 parts12

Similar boards

  • 4 layers25 × 35 mmQfn csi underpad diff, the printed circuit board in 3D

    Qfn csi underpad diff

    drandyhaas/KiCadRoutingTools

    A set of Python/Rust tools to aid routing in KiCad

    2 parts744MIT
  • 4 layers25.7 × 13 mmCpw test, the printed circuit board in 3D

    Cpw test

    loxodes/vna

    Under development open hardware microwave vector network analyzer

    2 parts205
  • 4 layers54 × 16 mmBnc test, the printed circuit board in 3D

    Bnc test

    azonenberg/starshipraider

    Open hardware test equipment

    2 parts193BSD-3-Clause
  • 4 layers94 × 53.4 mmMegaProgrammer, the printed circuit board in 3D

    MegaProgrammer

    clydeshaffer/gametank

    design files for the gametank hardware implementation

    2 parts150
  • 4 layers90.2 × 55.9 mmArduinox86 486 shield, the printed circuit board in 3D

    Arduinox86 486 shield

    dbalsom/arduinoX86

    An interface between an Arduino Due or Arduino GIGA and 8088, 8086, V20, V30, 186 or 286 CPUs

    2 parts114
  • 4 layers45.3 × 11.8 mmIdeswap, the printed circuit board in 3D

    Ideswap

    agranlund/raven

    Homemade MC68060 + DSP56303 Atari-compatible computer. Hardware, firmware, and software stack

    2 parts87
  • 4 layers39.4 × 53.3 mmSAB To RPi, the printed circuit board in 3D

    SAB To RPi

    whollender/SuperAudioBoard

    High quality, 24-bit audio codec board for Teensy 3.x

    2 parts75
  • 4 layers99.7 × 13 mmE Field 10cm, the printed circuit board in 3D

    E Field 10cm

    imendizabal/Near-Field-Probes

    Open Source kit of Near Field Probes for Electromagnetic Compatibility (EMC) troubleshooting

    2 parts59GPL-3.0