RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

cdefDebugDraw ReferencecdefGpuMesh ReferencecdefImgui ReferencecdefMath Referencecdefs ReferencecontrolSystems Referencecsvlib ReferencedelayLine Referencedequeue ReferencedevUtils ReferenceEvent Referenceextensions Referencefilters Referencegraphpath Referenceguihooks ReferenceinputFilters ReferenceinterpolatedMap Referenceintrospection ReferencejbeamWriter Referencejson-ast Referencejson ReferencejsonDebug ReferencejsonPrettyEncoderCustom Referencekdtreebox2d Referencekdtreebox3d Referencekdtreepoint3d Referencelpack ReferenceluaBinding ReferenceluaCore ReferenceluaProfiler Referencemathlib Referenceparticles Referencequadtree Referencesettings ReferencetcpServer ReferencetimeEvents Referenceutils Reference

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

jsonPrettyEncoderCustom Reference

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

jsonDebug Reference

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

kdtreebox2d Reference

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 Notes