0

If I do this:

SELECT *
FROM someTable
FOR JSON PATH

I get a single result.

I want each row of the table to output as a separate row containing the json for just that row.

Can that be done?

2 Answers 2

1

You can do this as a nested subquery. WITHOUT_ARRAY_WRAPPER will remove the [] around the JSON also

SELECT
  json = (
    SELECT p.*
    FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
  )
FROM someTable p;
Sign up to request clarification or add additional context in comments.

1 Comment

even more better - thank you
0

Never mind. I figured it out.

SELECT (SELECT *
        FROM someTable
        WHERE someUniqueColumn = p.someUniqueColumn
        FOR JSON PATH)
FROM someTable p

2 Comments

SELECT (SELECT p.* FOR JSON PATH) FROM someTable p
Even better - cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.