RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Debug DrawingGPU Mesh StructsImGui FFIMath Structs (FFI)FFI C DefinitionsPID ControllersCSV LibraryDelay LineDequeDevelopment UtilitiesEvent ReferenceExtension SystemSignal FiltersGraph PathfindingUI BridgeInput Filter Constants2D Bilinear InterpolationIntrospectionJBeam Pretty PrinterJSON AST ParserSJSON ParserJSON Debug ParserJSON Pretty PrinterK-D Tree (2D Boxes)K-D Tree (3D)K-D Tree (3D)Lua SerializerC++/Lua BindingLua CoreLua ProfilerMath LibraryParticlesQuadtreeSettingsTCP ServerTimer SchedulerUtility Library

UI

Resources

BeamNG Game Engine Lua Cheat SheetGE Developer RecipesMCP Server Setup

// RLS.STUDIOS=true

Premium Mods for BeamNG.drive. Career systems, custom vehicles, and immersive gameplay experiences.

Index

HomeProjectsPatreon

Socials

DiscordPatreon (RLS)Patreon (Vehicles)

© 2026 RLS Studios. All rights reserved.

Modding since 2024

API Referencecommon

JSON Pretty Printer

Module defined in `lua/common/jsonPrettyEncoderCustom.lua`. A customizable JSON pretty-printer with weighted key sorting and callback-controlled folding (inline vs expanded formatting).

Module defined in lua/common/jsonPrettyEncoderCustom.lua. A customizable JSON pretty-printer with weighted key sorting and callback-controlled folding (inline vs expanded formatting).


Exports

Functions

M.encode(v, lvl, numberPrecision, tableWeights, foldingCallback, _levelPath)

Encodes a Lua value as pretty-printed JSON with custom key ordering and folding control.

  • Parameters:
    • v - any - Value to encode
    • lvl - number|nil - Current indentation level (default: 1)
    • numberPrecision - number|nil - Decimal precision for non-integer numbers (nil = %.10g)
    • tableWeights - table - Map of key names (lowercase) to sort weights (1=first, 50=default, 99=last)
  • Returns: self (module table, for chaining)
    • _levelPath - string|nil - Internal path tracking (used by foldingCallback)
  • Returns: string - JSON string

Example:

local json = require('jsonPrettyEncoderCustom')
local result = json.encode(data, nil, nil,
  {control = 10, bindings = 99},  -- key sort weights
  function(item, lvl, path)        -- folding callback
    return path:sub(1,10) == '/bindings/' and tableSize(item) < 4
  end
)

Internal Notes

  • Key weights: 1 = first, 50 = default, 99 = last. Keys at same weight are sorted alphabetically
  • The folding callback receives the table item, indentation level, and a /-delimited path string
  • Handles: strings, numbers, booleans, tables (arrays and objects), vec3/quat cdata, nil → "null"
  • Infinity → 9e999, NaN → 9e999
  • Uses tableKeys() from utils for key extraction

See Also

  • cdefDebugDraw Reference - Related reference
  • cdefGpuMesh Reference - Related reference
  • cdefImgui Reference - Related reference
  • Common Libraries Overview - Guide

JSON Debug Parser

Module defined in `lua/common/jsonDebug.lua`. Debug variant of the SJSON parser that adds duplicate key detection. Structurally identical to `json.lua` but emits warnings when duplicate keys are found

K-D Tree (2D Boxes)

Module defined in `lua/common/kdtreebox2d.lua`. K-d tree implementation for 2D axis-aligned bounding boxes (4 dimensions: xmin, ymin, xmax, ymax). Supports efficient spatial range queries with both ne

On this page

ExportsFunctionsM.encode(v, lvl, numberPrecision, tableWeights, foldingCallback, _levelPath)Internal NotesSee Also