B4A Library [B4X] CodeBundle – Export Projects as a Single JSON for AI Analysis

The purpose of this tool is to easily export the complete project as a single json file which can be then fed to ChatGPT or any other capable AI bot for further analysis. It exports the modules code, layouts and some additional meta information.

This is an experimental tool. Please provide feedback if you find it useful or have any other suggestion.

Usage:

- Download the jar file and put it in the additional libraries folder, preferably under the B4X folder.
- Add to Main or B4XMainPage:
B4X:
#Macro: Title, Code bundle, ide://run?File=%ADDITIONAL%\..\B4X\CodeBundle.jar&Args=%PROJECT_NAME%
The path is set with the assumption that the additional libraries folder is set as recommended: https://www.b4x.com/android/forum/threads/b4x-additional-libraries-folder.103165/#content
Change it as needed.

- Click on Ctrl + 1 or the title bar button to export the project.

Notes:

- The following optional parameters are supported:

vmargs=-DHandleLayouts%3DFalse - To omit the layout files.
vmargs=-DCompactJson&3DFalse - To generate non-compact json.
vmargs=-DDontShowExplorer%3DTrue - Prevent file explorer from opening.

Source code is also attached.

- Save the project before running if you made changes. The tool reads the code from the project files.

Updates:

v0.31 - Fixed bug where first character was missing. Thanks @aeric for reporting.
v0.3 - #SignKeyPassword is removed from output.
Most regular libraries are now also added to the output.
v0.2 - API keys are replaced with all-zeros key. This is done heuristically based on several regex patterns. Replaced keys are logged. If you encounter a key that isn't replaced then please post an example.
Information about referenced b4xlibs is added to the output.

Download link: www.b4x.com/android/files/CodeBundle.jar
 

Attachments

  • Source code.zip
    8 KB · Views: 36
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Example with ChatGPT (plus):

I've generated the json of B4XTable project:

1766588118567.png


Output:

In B4XTable, there are 4 column types (constants on the class): TEXT, NUMBERS, DATE, VOID.

1) COLUMN_TYPE_TEXT​


  • SQL storage: created as TEXT.

Search: only TEXT columns are searchable (Searchable = True). Filtering uses LIKE ? on searchable columns.


Display: read with rs.GetString(...) and placed into the label; if search highlighting is enabled it can render highlighted matches.


Sort: sortable (like everything except VOID).

2) COLUMN_TYPE_NUMBERS​


  • SQL storage: INTEGER (note: even though you might insert doubles, the table schema uses INTEGER for non-text).

Search: not searchable.


Display: read with rs.GetDouble(...) and formatted via the column’s Formatter (defaults to DefaultDataFormatter).


Sort: sortable (SQL ORDER BY on the column).


3) COLUMN_TYPE_DATE​


  • SQL storage: INTEGER (date is stored as a Long ticks value, typical DateTime style).

  • Search: not searchable.

Display: read with rs.GetLong(...) and shown as DateTime.Date(longValue).


Sort: sortable.

4) COLUMN_TYPE_VOID​


  • Purpose: “UI-only” / placeholder columns (not part of the SQL data model).
  • SQL storage: not stored — VOID columns are skipped when building the SQL table, inserts, and selects.

Not bad.

First suggestion: Make it simple to generate json from b4xlibs. Will do...
 

JohnC

Expert
Licensed User
Longtime User
I haven't tried this tool yet, but one thought that came to mind is if this tool could incorporate a Conditional Symbol such as "CODEBUNDLE" so that it can automatically/optionally use alternative values for certain code/info that you don't want to send to the AI:
B4X:
#IF CODEBUNDLE
    APIKey = "xxxxxxxxxx"    'fake key
#ELSE
    APIKey = "AADD832-428HWEWLJEW-RWEYRWR"    'real key
#END IF

This way fake info will always be sent to the AI even in the event you forgot to manually switch build configurations before running this tool.
 
Last edited:

Mashiane

Expert
Licensed User
Longtime User
Wow, awesome, is there an option not to export particular file?

For example, I am using an env.json file to store security settings and other things for my project that I would not like to share with AI, will it be possible to have a command to exclude such an asset file?

Again, thanks so much for this tool. What a christmas present!! ;)
 

Magma

Expert
Licensed User
Longtime User
Here, tried for reversing... tried in simple projects seems working good (only some probs at headers)
 

Magma

Expert
Licensed User
Longtime User
The purpose of this tool is to easily export the complete project as a single json file which can be then fed to ChatGPT or any other capable AI bot for further analysis. It exports the modules code, layouts and some additional meta information.

...
While I acknowledge that this may diverge from the current scope, I believe the project's utility for third-party analysis and AI integration is outstanding. Providing a comprehensive, readable codebase rather than a compressed archive is a significant advantage.

We might consider extending this functionality to embed assets using Base64 encoding. (this would increase the output length and associated token costs, but in some cases can be fantastic)

Generally - The project/tool's fundamental approach is excellent.
 

byz

Active Member
Licensed User
Can the project be exported as JSON? This is interesting, but I don't quite understand.Is it for the library or the entire project?If you can import JSON as a project according to your rules. That third-party designer based on B4X becomes possible.
 

aeric

Expert
Licensed User
Longtime User
That third-party designer based on B4X becomes possible.
Basically, you can just ask AI to create/edit the design for you, give you back the updated JSON file and then you can convert it back to your project files. How good the AI can do, that is another question but at least it can "see" the project much better.
 

Magma

Expert
Licensed User
Longtime User
That’s an interesting idea, thanks. I think it would be better to place this option in the main menu of the b4j. Also, having an option to restore settings from a JSON file could be very useful.
 
Top