Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON object string formatted as simple string #70

Open
gitmalong opened this issue Oct 6, 2018 · 1 comment
Open

JSON object string formatted as simple string #70

gitmalong opened this issue Oct 6, 2018 · 1 comment

Comments

@gitmalong
Copy link

gitmalong commented Oct 6, 2018

My html:

<json-formatter json='attr.value' open='1'></json-formatter>

Is shown like this:

"{"globalId":"123","language":"en"}" (in green)

There is no way to expand it etc. Seems it is treated as simple string without object structure. If I enter my JSON code directly (as I get it when I put {{ attr.value }} in my template) it works fine and it is formatted correctly. I also made sure the JSON is valid.

I also tried

<json-formatter json='{{ attr.value }}' open='1'></json-formatter>

I'm clueless guys.

@billptacek
Copy link

billptacek commented Jun 29, 2021

I struggled with this as well, finally figured out the json-formatter expects an object, not a string. Wherever attr.value is defined, you need: attr.value = JSON.parse( json string value ); and then it will work.

attr.value = JSON.parse( "{globalId: 123, language: "en"}" );
<json-formatter json=attr.value open='1'></json-formatter>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants