<?xml version="1.0"?>
<ownershipDocument>

    <schemaVersion>X0508</schemaVersion>

    <documentType>4</documentType>

    <periodOfReport>2024-05-09</periodOfReport>

    <issuer>
        <issuerCik>0000785956</issuerCik>
        <issuerName>J&amp;J SNACK FOODS CORP</issuerName>
        <issuerTradingSymbol>JJSF</issuerTradingSymbol>
    </issuer>

    <reportingOwner>
        <reportingOwnerId>
            <rptOwnerCik>0001952646</rptOwnerCik>
            <rptOwnerName>Cranmer Robert</rptOwnerName>
        </reportingOwnerId>
        <reportingOwnerAddress>
            <rptOwnerStreet1>C/O J&amp;J SNACK FOODS CORP.</rptOwnerStreet1>
            <rptOwnerStreet2>350 FELLOWSHIP ROAD</rptOwnerStreet2>
            <rptOwnerCity>MOUNT LAUREL</rptOwnerCity>
            <rptOwnerState>NJ</rptOwnerState>
            <rptOwnerZipCode>08054</rptOwnerZipCode>
            <rptOwnerStateDescription></rptOwnerStateDescription>
        </reportingOwnerAddress>
        <reportingOwnerRelationship>
            <isOfficer>1</isOfficer>
            <officerTitle>Senior VP, Operations</officerTitle>
        </reportingOwnerRelationship>
    </reportingOwner>

    <aff10b5One>0</aff10b5One>

    <nonDerivativeTable>
        <nonDerivativeTransaction>
            <securityTitle>
                <value>Common stock, no par value</value>
            </securityTitle>
            <transactionDate>
                <value>2024-05-09</value>
            </transactionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>M</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionAmounts>
                <transactionShares>
                    <value>1500</value>
                </transactionShares>
                <transactionPricePerShare>
                    <value>125.83</value>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>A</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>3150</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                    <footnoteId id="F1"/>
                </directOrIndirectOwnership>
            </ownershipNature>
        </nonDerivativeTransaction>
        <nonDerivativeHolding>
            <securityTitle>
                <value>Common stock, no par value</value>
            </securityTitle>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>1416</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>I</value>
                </directOrIndirectOwnership>
                <natureOfOwnership>
                    <value>See footnote</value>
                    <footnoteId id="F2"/>
                </natureOfOwnership>
            </ownershipNature>
        </nonDerivativeHolding>
        <nonDerivativeTransaction>
            <securityTitle>
                <value>Common stock, no par value</value>
            </securityTitle>
            <transactionDate>
                <value>2024-05-09</value>
            </transactionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>S</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionAmounts>
                <transactionShares>
                    <value>2271</value>
                    <footnoteId id="F3"/>
                </transactionShares>
                <transactionPricePerShare>
                    <value>162.03</value>
                    <footnoteId id="F4"/>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>D</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>879</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </nonDerivativeTransaction>
        <nonDerivativeHolding>
            <securityTitle>
                <value>Common stock, no par value</value>
            </securityTitle>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>1416</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>I</value>
                </directOrIndirectOwnership>
                <natureOfOwnership>
                    <value>See footnote</value>
                    <footnoteId id="F2"/>
                </natureOfOwnership>
            </ownershipNature>
        </nonDerivativeHolding>
        <nonDerivativeTransaction>
            <securityTitle>
                <value>Common stock, no par value</value>
            </securityTitle>
            <transactionDate>
                <value>2024-05-09</value>
            </transactionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>S</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionAmounts>
                <transactionShares>
                    <value>7</value>
                </transactionShares>
                <transactionPricePerShare>
                    <value>162.98</value>
                    <footnoteId id="F5"/>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>D</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>872</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </nonDerivativeTransaction>
        <nonDerivativeHolding>
            <securityTitle>
                <value>Common stock, no par value</value>
            </securityTitle>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>1416</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>I</value>
                </directOrIndirectOwnership>
                <natureOfOwnership>
                    <value>See footnote</value>
                    <footnoteId id="F2"/>
                </natureOfOwnership>
            </ownershipNature>
        </nonDerivativeHolding>
        <nonDerivativeTransaction>
            <securityTitle>
                <value>Common stock, no par value</value>
            </securityTitle>
            <transactionDate>
                <value>2024-05-09</value>
            </transactionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>I</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionAmounts>
                <transactionShares>
                    <value>1140</value>
                    <footnoteId id="F6"/>
                </transactionShares>
                <transactionPricePerShare>
                    <value>162.61</value>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>D</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>276</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>I</value>
                </directOrIndirectOwnership>
                <natureOfOwnership>
                    <value>See footnote</value>
                    <footnoteId id="F2"/>
                </natureOfOwnership>
            </ownershipNature>
        </nonDerivativeTransaction>
        <nonDerivativeHolding>
            <securityTitle>
                <value>Common stock, no par value</value>
            </securityTitle>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>872</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </nonDerivativeHolding>
    </nonDerivativeTable>

    <derivativeTable>
        <derivativeTransaction>
            <securityTitle>
                <value>Options to Purchase</value>
            </securityTitle>
            <conversionOrExercisePrice>
                <value>125.83</value>
            </conversionOrExercisePrice>
            <transactionDate>
                <value>2024-05-09</value>
            </transactionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>M</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionAmounts>
                <transactionShares>
                    <value>1500</value>
                </transactionShares>
                <transactionPricePerShare>
                    <value>0</value>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>D</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <exerciseDate>
                <value>2023-05-20</value>
            </exerciseDate>
            <expirationDate>
                <value>2025-05-19</value>
            </expirationDate>
            <underlyingSecurity>
                <underlyingSecurityTitle>
                    <value>Common Stock, no par, value</value>
                </underlyingSecurityTitle>
                <underlyingSecurityShares>
                    <value>1500</value>
                </underlyingSecurityShares>
            </underlyingSecurity>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>0</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </derivativeTransaction>
    </derivativeTable>

    <footnotes>
        <footnote id="F1">Includes 390 shares purchased by the Reporting Person through the J &amp; J Snack Foods Corp. 1996 Employee Stock Purchase Plan.</footnote>
        <footnote id="F2">Represents shares owned by Mr. Cranmer in his J &amp; J Snack Foods Corp. 401K Profit Sharing Plan.</footnote>
        <footnote id="F3">Includes 390 shares previously purchased by the Reporting Person in the J &amp; J Snack Foods Corp. 1996 Employee Stock Purchase Plan.</footnote>
        <footnote id="F4">The price reported in column 4 is a weighted average price.  These shares were sold in multiple transactions at prices ranging from $161.52 to $162.46.  The Reporting Person undertakes to provide to the Company, any security holder of the Company, or the staff of the Securities and Exchange Commission, upon request, full information regarding the number of shares sold at each separate price with the range set forth in footnote 4 of this Form 4</footnote>
        <footnote id="F5">The price reported in column 4 is a weighted average price.  These shares were sold in multiple transactions at prices ranging from $162.53 to $163.05.  The Reporting Person undertakes to provide to the Company, any security holder of the Company, or the staff of the Securities and Exchange Commission, upon request, full information regarding the number of shares sold at each separate price with the range set forth in footnote 5 of this Form 4</footnote>
        <footnote id="F6">Represents shares sold under the J &amp; J Snack Foods Corp. 401K Profit Sharing Plan.</footnote>
    </footnotes>

    <ownerSignature>
        <signatureName>/s/ Michael A. Pollner, Attorney in Fact</signatureName>
        <signatureDate>2024-05-13</signatureDate>
    </ownerSignature>
</ownershipDocument>
