Standard Library Symbols
This page contains documentation for symbols in the standard library of the JsonPatcher language. This is separate from the symbols added by the mod and symbols available to datapacks and resource packs
Namespace reflect
Library reflection
A library containing utilities for interacting with the parent JVM.
This module can be dangerous if given to untrusted code, and is thus placed in its own library group: reflection
Any code using this library should make sure to not allow outside code to call arbitrary java code.
libgroup(reflection)
Function reflect.reflection.convertArray: (class: JavaClass, value: any*) -> JavaObject
Utility function to convert a JsonPatcher array into a Java array. Takes in the component type of the array and the values to convert.
Function reflect.reflection.findClass: (name: string) -> JavaClass
Finds a Java class and loads it into a JsonPatcher value.
The class is looked up by java.lang.Class#forName, with the same syntax as that method.
Function reflect.reflection.makeArray: (class: JavaClass, size: number, fill: any?) -> JavaObject
Utility function to instantiate a Java array of a certain class. Takes in the component type of the array, the size of the array and an optional value to fill it with.
Type JavaClass based on special
Represents a java class. Inner classes as well as static methods and fields are available as properties. In case of name conflicts, you can specify the jvm method or field descriptor.
Constructors are available either by calling the class object as a function or via methods named <init>,
which must have their signature specified.
Property reflect.JavaClass.*: unknown
Inner classes as well as static methods and fields are available as properties on classes. They can be referred to by their simple Java names unless there are conflicts, in which case a full descriptor needs to be specified.
Property reflect.JavaClass.class: JavaObject
A special property on class values. Allows scripts to access the java.lang.Class instance corresponding to the class.
Type JavaObject based on special
An object representing a java object. Both arrays and regular objects are represented with this class.
For regular objects methods and fields can be accesses similar to static ones on JavaClass.
Arrays can be indexed using jsonpatcher indexing operators. Their length field is also exposed.
Property reflect.JavaObject.*: unknown
Instance methods and fields are available as properties on classes. They can be referred to by their simple Java names unless there are conflicts, in which case a full descriptor needs to be specified.
Additionally the length of java arrays can be accessed using the length property.
Namespace std
Global library arrays
The arrays library contains functions for manipulating arrays. All of them can be used as methods on arrays.
Function std.arrays.filter: <$T>(array: $T[], predicate: ($T) -> boolean) -> $T[]
Applies the specified function to each element in the array, creating a new array with only the elements that returned true.
Function std.arrays.indexOf: (array: array, value: any) -> number
Returns the index of the index of the value in the array, or -1 if it isn't present
Function std.arrays.insert: <$T>(array: $T[], index: number, value: $T) -> $T[]
Inserts the specified value at the specified index. The inserted value will be found that the index after the insertion.
Function std.arrays.map: <$T, $U>(array: $T[], function: ($T) -> $U) -> $U[]
Applies the specified function to each element in the array, creating a new array and returns the result.
Function std.arrays.pop: <$T>(array: $T[]) -> $T
Removes the last element from the array and returns it.
Function std.arrays.push: <$T>(array: $T[], value: $T) -> $T[]
Appends the specified value to the end of the array. Returns the array.
Function std.arrays.reduce: <$T, $A>(array: $T[], function: (value: $T, accumulator: $A) -> $A, initial: $A) -> $A
Iterates through the array applying the specified function to each element and the current state, beginning with the initial value and being replaced by the returned value from the function. Returns the last state.
Function std.arrays.remove: <$T>(array: $T[], value: any) -> $T[]
Removes the first occurrence of the specified value from the array. Returns the array.
Function std.arrays.removeAt: <$T>(array: $T[], index: number) -> $T
Removes the value at the specified index from the array. Returns the removed element.
Function std.arrays.removeIf: <$T>(array: $T[], predicate: ($T) -> boolean) -> $T[]
Applies the specified function to each element in the array, removing the elements that returned true.
Function std.arrays.replace: <$T, $U>(array: $T[], function: ($T) -> $U) -> $U[]
Applies the specified function to each element in the array modifying them in place
Function std.arrays.slice: <$T>(array: $T[], from: number, to: number?) -> $T[]
Returns a slice of the array from the specified start index (inclusive) to the specified end index (exclusive)
Global library debug
Provides various functions for debugging code.
Function std.debug.assert: (value: any, message: string?) -> null
Checks if the value is truthy. If it is nothing happens. If it isn't, then an error is thrown.
Function std.debug.assertEquals: (first: any, second: any) -> null
Checks if the two values are equal. If they are nothing happens. If they aren't, then an error is thrown.
Function std.debug.log: (message: any) -> null
Logs a message to console.
Function std.debug.throw: (message: any) -> null
Throws an error. Use this if your code gets in situations it shouldn't.
Global library functions
Provides utilities for working with functions. Some of the can be used as methods on function objects.
Function std.functions.bind: (function: function, arg: any, index: number?) -> function
Binds the specified argument to the function at the specified index or 0 if none is provided.
Function std.functions.constant: <$T>(value: $T) -> () -> $T
Returns a function that always returns the specified value.
Function std.functions.identity: () -> <$T>(value: $T) -> $T
Returns a function that returns its single argument.
Function std.functions.then: (function: function, then: function) -> function
Creates a new function that calls the first function and then calls the second function on it's return value.
Global library math
The math library contains many functions for performing mathematical operations.
Property std.math.E: number
Property std.math.NEGATIVE_INFINITY: number
Property std.math.NaN: number
Property std.math.PI: number
Property std.math.POSITIVE_INFINITY: number
Function std.math.abs: (input: number) -> number
Function std.math.acos: (input: number) -> number
Function std.math.asin: (input: number) -> number
Function std.math.atan: (input: number) -> number
Function std.math.cbrt: (input: number) -> number
Function std.math.ceil: (input: number) -> number
Function std.math.cos: (input: number) -> number
Function std.math.cosh: (input: number) -> number
Function std.math.exp: (input: number) -> number
Function std.math.floor: (input: number) -> number
Function std.math.log: (input: number) -> number
Function std.math.log10: (input: number) -> number
Function std.math.max: (first: number, second: number) -> number
Function std.math.min: (first: number, second: number) -> number
Function std.math.signum: (input: number) -> number
Function std.math.sin: (input: number) -> number
Function std.math.sinh: (input: number) -> number
Function std.math.sqrt: (input: number) -> number
Function std.math.tan: (input: number) -> number
Function std.math.tanh: (input: number) -> number
Global library objects
Provides utilities for working with objects.
Function std.objects.keys: (object: object) -> string[]
Returns the list of keys in a object.
Global library strings
Provides utilities for manipulating strings. Many of the methods in this module can be used as methods.
Function std.strings.asString: (value: any) -> string
Converts any value to a string
Function std.strings.charAt: (string: string, index: number) -> string
Returns a string consisting of only the character at the specified index
Function std.strings.chars: (string: string) -> array
Returns an array of strings with each character from this string
Function std.strings.contains: (string: string, substring: string) -> boolean
Returns true if the string contains the specified substring
Function std.strings.endsWith: (string: string, suffix: string) -> boolean
Returns true if the string ends with the specified suffix
Function std.strings.isBlank: (string: string) -> boolean
Returns true if the string only contains whitespace characters
Function std.strings.isEmpty: (string: string) -> boolean
Returns true if the string is empty (length == 0)
Function std.strings.join: (array: array, string: delimiter) -> string
Converts all values in the array to a string and concatenates them with the delimiter in between
Function std.strings.length: (string: string) -> number
Returns the length of the string in unicode code units
Function std.strings.matches: (string: string, regex: string) -> boolean
Checks if the whole string matches a specific regular expression.
Function std.strings.replace: (string: string, pattern: string, replacement: string) -> string
Replaces all instances of pattern in string with replacement.
Function std.strings.replaceRegex: (string: string, pattern: string, replacement: string) -> string
Replaces all matches of the regular expression pattern in string with replacement.
Function std.strings.split: (string: string, delimiter: string) -> array
Splits the string into into an array with the specified delimiter
Function std.strings.startsWith: (string: string, prefix: string) -> boolean
Returns true if the string starts with the specified prefix
Function std.strings.substring: (string: string, from: number, to: number?) -> string
Returns a substring from the specified start index (inclusive) to the specified end index, if specified (exclusive)
Function std.strings.toLowerCase: (string: string) -> string
Converts the string to lowercase with the root locale
Function std.strings.toUpperCase: (string: string) -> string
Converts the string to uppercase with the root locale
Function std.strings.trim: (string: string) -> string
Trim the string by removing leading and trailing whitespace
Function std.strings.trimEnd: (string: string) -> string
Trim the string by removing trailing whitespace
Function std.strings.trimStart: (string: string) -> string
Trim the string by removing leading whitespace
Global library values
Provides utilities for working with values.
Function std.values.freeze: <$T>(value: $T) -> $T
Freezes a value, causing it to be immutable.
For objects and arrays this function returns a new object or array respectively which forbids mutations by throwing an error. Numbers, strings, booleans, functions and null are passed through as is.
Function std.values.getProperty: (value: any, property: string) -> unknown
Gets a property from a value by name, even if it isn't an object. This function is fairly slow, and should only be used as a last resort. For regular objects, please use the indexing operator instead.
Function std.values.setProperty: (value: any, property: string, newValue: unknown) -> null
Sets a property on a value by name, even if it isn't an object. This function is fairly slow, and should only be used as a last resort. For regular objects, please use the indexing operator instead.
Metadata tag @version: string
Declares the version of a JsonPatcher file. Currently only version 2 is supported. Any other version may result in the file getting rejected.
Unknown object array
Property std.array.length: number
The amount of elements in the array