Bitbybit Docs
    Preparing search index...

    Class JSONBitByBit

    Reading and changing values inside JSON data. A path such as $.parts[0].name follows the JSONPath syntax: $ is the root, .name steps into a property, [0] into a list entry and ..name searches at any depth. The methods here query, set and list by path, work on single properties and preview data through the application; every change comes back as a changed copy, the input stays as it is.

    Index

    Constructors

    create

    • Gives a new empty object with no properties, a starting point for setValueOnProp and setValue.

      Returns any

      An empty object

      const settings = bitbybit.json.createEmpty();
      const withWidth = bitbybit.json.setValueOnProp({ json: settings, property: "width", value: 10 });

    jsonpath

    • Finds every value in the JSON that a JSONPath expression matches and gives them as a list, even when there is only one.

      $.parts[*].name lists all part names and $..radius every radius at any depth; JSONPath filters in square brackets narrow the matches by a condition.

      Parameters

      • inputs: QueryDto

        The JSON and the JSONPath expression

      Returns any

      The matching values as a list

      const names = bitbybit.json.query({ json: model, query: "$.parts[*].name" });
      
    • Sets property prop to value on every object a JSONPath expression reaches, giving a changed copy of the JSON.

      path points at the parent objects, prop names the property on them: path: "$.parts[*]", prop: "visible" changes every part. A value that is not an object throws an error.

      Parameters

      • inputs: SetValueDto

        The JSON, the path to the parent objects, the property name and the value

      Returns any

      The changed copy

      const hidden = bitbybit.json.setValue({ json: model, path: "$.parts[*]", prop: "visible", value: false });
      
    • Applies several setValue changes in one go: entry i of paths, props and values is one change, applied in order to a copy of the JSON.

      Parameters

      • inputs: SetValuesOnPathsDto

        The JSON and the matching lists of paths, property names and values

      Returns any

      The changed copy

      const updated = bitbybit.json.setValuesOnPaths({ json: model, paths: ["$", "$.parts[0]"], props: ["name", "visible"], values: ["Assembly", false] });
      
    • Lists the paths of every value a JSONPath expression matches, each as a full path from the root such as $['parts'][0]['name'], instead of the values themselves.

      Parameters

      • inputs: PathsDto

        The JSON and the JSONPath expression

      Returns any

      The paths of the matches, as a list of strings

      const where = bitbybit.json.paths({ json: model, query: "$..radius" });
      

    preview

    • Hands the JSON to the running application to show it and offer to save it as a file; the application decides how the preview looks, and nothing happens when the value is empty.

      Parameters

      Returns void

      Nothing

      bitbybit.json.previewAndSaveJson({ json: model });
      
    • Hands the JSON to the running application to show it; the application decides how the preview looks, and nothing happens when the value is empty.

      Parameters

      Returns void

      Nothing

      bitbybit.json.previewJson({ json: model });
      

    props

    • Sets one top-level property of a JSON object to a value, giving a changed copy; the input stays as it is and a property that did not exist is added.

      Parameters

      Returns any

      The changed copy

      const updated = bitbybit.json.setValueOnProp({ json: settings, property: "width", value: 20 });
      
    • Finds the first object in a list whose property equals the given value, comparing with strict equality, and gives it back; nothing matching gives undefined.

      For anything beyond one property, use query with a filter.

      Parameters

      Returns any

      The first matching object, or undefined

      const part = bitbybit.json.getJsonFromArrayByFirstPropMatch({ jsonArray: parts, property: "name", match: "lid" });
      
    • Reads one top-level property of a JSON object; a missing property gives undefined.

      Parameters

      Returns any

      The property's value

      const width = bitbybit.json.getValueOnProp({ json: settings, property: "width" });
      

    transform

    • Turns any JSON-compatible value into its JSON text, on one line without indentation, as JSON.stringify does.

      Parameters

      Returns string

      The JSON text

      const text = bitbybit.json.stringify({ json: { width: 10, points: [[0, 0, 0], [1, 1, 1]] } });
      
    • Turns JSON text into the value it describes, as JSON.parse does; text that is not valid JSON throws an error.

      Parameters

      Returns any

      The parsed value

      const points = bitbybit.json.parse({ text: "[[0, 0, 0], [1, 1, 1]]" });