Fold only items located in root in a JSON editor

Hey there,

I have a use case which I need to fold only the first level of json.

e,g, this json:

  "0": {
    "a": 1
  "1": {
    "b": 2

I want to folded like this:


And not:


I tried to look at foldEffect/foldInside but i am not sure how it can help and how.

Thanks you very much in advance :pray:

You could walk the syntax tree to find all the lines that start a 1st-level nesting, collect foldEffects for those lines, and dispatch those. For big documents it may be somewhat tricky to get the editor to parse the entire document, but you can use ensureSyntaxTree if you want to force it to do that immediately.

Thanks @marijn for the response.
How can I detect that a node is start a 1st level nesting?

I am doing something like that:

                        enter: (node) => {
                           //do something here

I guess i need to collect them, but how?

How can I detect out of node if it start a 1st-level nesting?

@marijn Sorry for nudging, I really need your help here :pray:

I’m sorry, I don’t have the time or energy to help people write specific code here. I provide the library, I wrote docs, if you can’t take it from there you’ll have to do more studying or hire someone to implement this.