Skip to content

CrowdHailer/julienne

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

julienne

Package Version Hex Docs

A JSON parser that produces a flat representation of the decoded JSON. Decoded vales are a list of terms with depth information, rather than nested data structures. This approach is required when working in an environment that doesn't support recursive data structures.

Usage

gleam add julienne@1
import julienne

pub fn main() {
  let assert Ok(tokens) = julienne.parse("true")
  // Returns: [#(Boolean(True), 0)]

  let assert Ok(tokens) = julienne.parse("null")
  // Returns: [#(Null, 0)]

  let assert Ok(tokens) = julienne.parse("\"hello\"")
  // Returns: [#(String("hello"), 0)]

  let assert Ok(tokens) = julienne.parse("123")
  // Returns: [#(Integer(123), 0)]

  let assert Ok(tokens) = julienne.parse("1.5e10")
  // Returns: [#(Number(Positive, 1, #(5, 1), 10), 0)]

  let assert Ok(tokens) = julienne.parse("[true, false, null]")
  // Returns: [
  //   #(Array, 0),
  //   #(Boolean(True), 1),
  //   #(Boolean(False), 1),
  //   #(Null, 1)
  // ]

  let assert Ok(tokens) = julienne.parse("{\"a\": true, \"b\": false}")
  // Returns: [
  //   #(Object, 0),
  //   #(Field("a"), 1),
  //   #(Boolean(True), 1),
  //   #(Field("b"), 1),
  //   #(Boolean(False), 1)
  // ]

  let assert Ok(tokens) = julienne.parse("{\"a\": {\"b\": false, \"c\": {}}}")
  // Returns: [
  //   #(Object, 0),
  //   #(Field("a"), 1),
  //   #(Object, 1),
  //   #(Field("b"), 2),
  //   #(Boolean(False), 2),
  //   #(Field("c"), 2),
  //   #(Object, 2)
  // ]
}

How It Works

The parser converts JSON into a flat list of Term values, where each term includes:

  • The token type (Boolean, Null, String, Integer, Number, Array, Object, or Field)
  • The depth level (0 for root, 1 for first level of nesting, etc.)

Development

gleam run   # Run the project
gleam test  # Run the tests

Further documentation can be found at https://hexdocs.pm/julienne.

Credit

Created for EYG, a new integration focused programming language.

About

A JSON parser that decodes JSON into a flat (non recursive) data structure.

Resources

Stars

Watchers

Forks

Contributors

Languages