Skip to content

feat: Support JSON as data type #4516

Open
2 of 5 issues completed
Open

Description

@eddyxu

Support JSON as data type

Users are expecting to store schema less json blobs in the dataset. In other systems,

  • Postgres can use jsonb type
  • Spark offers functions, such as get_json_object / json_object_keys function on json strings.
  • Pyarrow has JsonType now

It'd be beneficial for Lance to have capability to store, access and search json objects.

  • Store JSON as one of the arrow field.
  • Implement reading values by key or json path.
  • Create index on one of the scalar field.
  • Search a scalar json field
  • Create vector index on one of vector field.
  • Search a vector json field
  • Create full text index on one of the string field.
  • Search a fulltext json field.

Sub-issues

Sub-issues

2 of 5 Issues completed
Loading 5 sub-issues

Activity

  1. added
    enhancement
    epic
    on Aug 20, 2025
  2. self-assigned this
    on Aug 20, 2025
  3. westonpace commented on Aug 20, 2025

    @westonpace
    Member

    I think adding JSON to file format (e.g. variant or something, if needed) and adding JSON to the table format (JSON indexes) and adding JSON to the compute engine (JSON functions) can all be tackled independently.

    The file format and compute engine changes are probably more well understood.

    The table format changes are a little less understood to me. There is maybe an easy path for some kind of read-only JSON column where a write means rewriting the entire JSON value. Making a full schema-less table will be quite different.

    Is a user going to want to change a JSON value for a row (e.g. an update)? Will they want to add a new JSON column (to an existing JSON object)?

  4. westonpace commented on Aug 20, 2025

    @westonpace
    Member

    I assume if we are training a vector index on a vector field and that field isn't a vector type on some row (JSON does not enforce homogenous types) or if the vector has different dimensions then we just skip the field?

    What should we use to determine the dimension of the JSON vector field? Should it be the first value we encounter?

  5. wjones127 commented on Aug 20, 2025

    @wjones127
    Contributor

    One good option is to join the effort in DataFusion to support the Parquet Variant data type. (It's just called Parquet Variant because that's where the standard was defined, not because it's tied to parquet.)

    Similar to how we can add geospatial support by just including a few plugins (see demo from #4482), we could probably add variant support with a few plugins.

    Relevant packages:

  6. wjones127 commented on Aug 20, 2025

    @wjones127
    Contributor
  7. Xuanwo commented on Aug 22, 2025

    @Xuanwo
    Member

    I think the variant approach works well for shredding support. Our ultimate goal is to support variants in Lance. However, we can begin by adding JSON support through the introduction of jsonb first. We have a mature jsonb crate and it has nearly everthing we need so far.

    My current plan:

    • Allow users to write data in json
    • We encode json into jsonb binary as a logic type
    • We store the binary as LargeBinary in lance

    The first MVP will allow users to:

    • write json data in arrow
    • read json data by get_json_path
  8. wojiaodoubao commented on Sep 5, 2025

    @wojiaodoubao
    Contributor

    Our current JSON index is defined as follows. I think we can also support full-text indexes for JSON column. As the number of fields/paths in JSON can be very large, it is impractical to create an index for each field. Full-text indexing allows querying all fields of json data in one index, making it more practical and useful.

    /// A JSON index that indexes a field in a JSON column
    ///
    /// The underlying index can be any other type of scalar index
    #[derive(Debug)]
    pub struct JsonIndex {
        target_index: Arc<dyn ScalarIndex>,
        path: String,
    }
    

    The key to building full-text indexing for JSON is how to tokenize it. We can refer to Tantivy's JSON Indexing Design.

    For example, given the following JSON:

    {
        "user": {
            "name": "Paul Masurel",
            "address": {
                "city": "Tokyo",
                "country": "Japan"
            },
            "created_at": "2018-11-12T23:20:50.52Z"
        }
    }
    

    The tokens generated would be:

    • ("name", Text, "Paul")
    • ("name", Text, "Masurel")
    • ("address.city", Text, "Tokyo")
    • ("address.country", Text, "Japan")
    • ("created_at", Date, 15420648505)

    To implement this, we just need to create a new tokenizer (may be call it JsonTokenizer).

    • For JSON data, parse it into (json_path, value_type, value) tokens.
    • For FST queries, such as MatchQuery("my_path.my_segment:233"), convert it into tokens like (my_path.my_segment, String, 233) and (my_path.my_segment, u64, 233), and perform an Operator::Or query.

    cc @jackye1995 @Xuanwo

  9. westonpace commented on Sep 16, 2025

    @westonpace
    Member

    Yes, a full text JSON index like the one in tantivy would be very cool.

  10. wirybeaver commented on Jun 21, 2026

    @wirybeaver
    Contributor

    Opened draft PR #7377 for this.

    Motivation: Lance JSON inverted indexing needs to preserve array-of-object structure instead of treating each row as one token stream. Tantivy documents the flaw of a bag-of-terms JSON array index: a query like cart.product_type:sneakers AND cart.attributes.color:red can match even when sneakers and red live in different objects in the same array.

    By porting the idea of Apache Pinot Json Index which I worked on previously, this PR addresses that class of false positive with FlattenedSubDocs: each JSON row is flattened into sub-docs, related path constraints can be evaluated inside the same flattened array element, and matches are then mapped back to the original Lance row id.

    The PR also keeps existing JSON indexes readable, preserves positional/wildcard differences like foo[0].bar[0],str,y vs foo[0].bar[*],str,y, and adds disable_cross_array_unnest=false by default with a Pinot-style opt-in to avoid Cartesian sub-doc growth when users accept reduced accuracy for cross-array query constraints.

    @westonpace @wojiaodoubao @jackye1995 Could you take an early review of the PR proposal to see if there are any major concerns? I've included detailed examples throughout to make it easier for reviewers to understand the proposed solution.

  11. wirybeaver commented on Jun 24, 2026

    @wirybeaver
    Contributor

    @eddyxu @Xuanwo Could you take a look when you are available for this JSON Indexing improvement proposal? #7377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementepic

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions