JsonPatcher Docsbeta

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

Type JavaClass of 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 JavaClass.*

Type: 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 JavaClass.class

Type: JavaObject

A special property on class values. Allows scripts to access the java.lang.Class instance corresponding to the class.

Type JavaObject of 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 JavaObject.*

Type: 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.

Unknown object array

Property array.length

Type: number
Available as a method on arrays

The amount of elements in the array

Global library arrays

The arrays library contains functions for manipulating arrays. All of them can be used as methods on arrays.

Function arrays.pop

Type: <$T>(array: $T[]) -> $T
Available as a method on arrays

Removes the last element from the array and returns it.

Function arrays.filter

Type: <$T>(array: $T[], predicate: ($T) -> boolean) -> $T[]
Available as a method on arrays

Applies the specified function to each element in the array, creating a new array with only the elements that returned true.

Function arrays.reduce

Type: <$T, $A>(array: $T[], function: (value: $T, accumulator: $A) -> $A, initial: $A) -> $A
Available as a method on arrays

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 arrays.slice

Type: <$T>(array: $T[], from: number, to: number?) -> $T[]
Available as a method on arrays

Returns a slice of the array from the specified start index (inclusive) to the specified end index (exclusive)

Function arrays.replace

Type: <$T, $U>(array: $T[], function: ($T) -> $U) -> $U[]
Available as a method on arrays

Applies the specified function to each element in the array modifying them in place

Function arrays.insert

Type: <$T>(array: $T[], index: number, value: $T) -> $T[]
Available as a method on arrays

Inserts the specified value at the specified index. The inserted value will be found that the index after the insertion.

Function arrays.removeAt

Type: <$T>(array: $T[], index: number) -> $T
Available as a method on arrays

Removes the value at the specified index from the array. Returns the removed element.

Function arrays.map

Type: <$T, $U>(array: $T[], function: ($T) -> $U) -> $U[]
Available as a method on arrays

Applies the specified function to each element in the array, creating a new array and returns the result.

Function arrays.indexOf

Type: (array: array, value: any) -> number
Available as a method on arrays

Returns the index of the index of the value in the array, or -1 if it isn't present

Function arrays.push

Type: <$T>(array: $T[], value: $T) -> $T[]
Available as a method on arrays

Appends the specified value to the end of the array. Returns the array.

Function arrays.remove

Type: <$T>(array: $T[], value: any) -> $T[]
Available as a method on arrays

Removes the first occurrence of the specified value from the array. Returns the array.

Function arrays.removeIf

Type: <$T>(array: $T[], predicate: ($T) -> boolean) -> $T[]
Available as a method on arrays

Applies the specified function to each element in the array, removing the elements that returned true.

Global library debug

Provides various functions for debugging code.

Function debug.log

Type: (message: any) -> null

Logs a message to console.

Function debug.throw

Type: (message: any) -> null

Throws an error. Use this if your code gets in situations it shouldn't.

Function debug.assert

Type: (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 debug.assertEquals

Type: (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.

Global library functions

Provides utilities for working with functions. Some of the can be used as methods on function objects.

Function functions.bind

Type: (function: function, arg: any, index: number?) -> function
Available as a method on functions
This property has special behaviour in the typechecker

Binds the specified argument to the function at the specified index or 0 if none is provided.

Function functions.constant

Type: <$T>(value: $T) -> () -> $T

Returns a function that always returns the specified value.

Function functions.identity

Type: () -> <$T>(value: $T) -> $T

Returns a function that returns its single argument.

Function functions.then

Type: (function: function, then: function) -> function
Available as a method on functions
This property has special behaviour in the typechecker

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 math.E

Type: number

Function math.log

Type: (input: number) -> number

Function math.cos

Type: (input: number) -> number

Function math.log10

Type: (input: number) -> number

Function math.atan

Type: (input: number) -> number

Function math.cbrt

Type: (input: number) -> number

Function math.tanh

Type: (input: number) -> number

Property math.NEGATIVE_INFINITY

Type: number

Function math.min

Type: (first: number, second: number) -> number

Function math.sqrt

Type: (input: number) -> number

Function math.sin

Type: (input: number) -> number

Property math.NaN

Type: number

Function math.exp

Type: (input: number) -> number

Function math.floor

Type: (input: number) -> number

Function math.tan

Type: (input: number) -> number

Function math.signum

Type: (input: number) -> number

Function math.sinh

Type: (input: number) -> number

Function math.max

Type: (first: number, second: number) -> number

Function math.acos

Type: (input: number) -> number

Function math.ceil

Type: (input: number) -> number

Function math.cosh

Type: (input: number) -> number

Property math.POSITIVE_INFINITY

Type: number

Function math.abs

Type: (input: number) -> number

Property math.PI

Type: number

Function math.asin

Type: (input: number) -> number

Global library objects

Provides utilities for working with objects.

Function objects.keys

Type: (object: object) -> string[]

Returns the list of keys in a object.

Global 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.

Function reflection.makeArray

Type: (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.

Function reflection.convertArray

Type: (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 reflection.findClass

Type: (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.

Global library strings

Provides utilities for manipulating strings. Many of the methods in this module can be used as methods.

Function strings.toLowerCase

Type: (string: string) -> string
Available as a method on strings

Converts the string to lowercase with the root locale

Function strings.replace

Type: (string: string, pattern: string, replacement: string) -> string
Available as a method on strings

Replaces all instances of pattern in string with replacement.

Function strings.length

Type: (string: string) -> number
Available as a method on strings

Returns the length of the string in unicode code units

Function strings.isEmpty

Type: (string: string) -> boolean
Available as a method on strings

Returns true if the string is empty (length == 0)

Function strings.isBlank

Type: (string: string) -> boolean
Available as a method on strings

Returns true if the string only contains whitespace characters

Function strings.trimEnd

Type: (string: string) -> string
Available as a method on strings

Trim the string by removing trailing whitespace

Function strings.matches

Type: (string: string, regex: string) -> boolean
Available as a method on strings

Checks if the whole string matches a specific regular expression.

Function strings.replaceRegex

Type: (string: string, pattern: string, replacement: string) -> string
Available as a method on strings

Replaces all matches of the regular expression pattern in string with replacement.

Function strings.substring

Type: (string: string, from: number, to: number?) -> string
Available as a method on strings

Returns a substring from the specified start index (inclusive) to the specified end index, if specified (exclusive)

Function strings.contains

Type: (string: string, substring: string) -> boolean
Available as a method on strings

Returns true if the string contains the specified substring

Function strings.split

Type: (string: string, delimiter: string) -> array
Available as a method on strings

Splits the string into into an array with the specified delimiter

Function strings.trim

Type: (string: string) -> string
Available as a method on strings

Trim the string by removing leading and trailing whitespace

Function strings.toUpperCase

Type: (string: string) -> string
Available as a method on strings

Converts the string to uppercase with the root locale

Function strings.endsWith

Type: (string: string, suffix: string) -> boolean
Available as a method on strings

Returns true if the string ends with the specified suffix

Function strings.asString

Type: (value: any) -> string

Converts any value to a string

Function strings.join

Type: (array: array, string: delimiter) -> string

Converts all values in the array to a string and concatenates them with the delimiter in between

Function strings.trimStart

Type: (string: string) -> string
Available as a method on strings

Trim the string by removing leading whitespace

Function strings.charAt

Type: (string: string, index: number) -> string
Available as a method on strings

Returns a string consisting of only the character at the specified index

Function strings.chars

Type: (string: string) -> array
Available as a method on strings

Returns an array of strings with each character from this string

Function strings.startsWith

Type: (string: string, prefix: string) -> boolean
Available as a method on strings

Returns true if the string starts with the specified prefix

Global library values

Provides utilities for working with values.

Function values.freeze

Type: <$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 values.getProperty

Type: (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 values.setProperty

Type: (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

Type: string

Declares the version of a JsonPatcher file. Currently only version 2 is supported. Any other version may result in the file getting rejected.