Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8025497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:10:59+00:00 2026-06-04T23:10:59+00:00

I am writing a program that generates JSON and outputs it to the file.

  • 0

I am writing a program that generates JSON and outputs it to the file. The first content that I output to the file is the following JSON string:

var jsonStyle = {'color': '#004070',
    'weight': 2,
    'opacity': 0.9}

Then I use the Python JSON library to generate JSON output. This is the Python object that I pass into json.dumps:

js = {'type': 'Feature',
      'properties':
          {'style': 'jsonStyle'},
      'geometry': geomJSON}

What I want the text output to be is:

js = {'type': 'Feature',
      'properties':
          {'style': jsonStyle},
      'geometry': geomJSON}

This way I can edit jsonStyle at the top of my output file to change the style for all subsequent JSON elements. The issue is, the current way I structure the JSON object outputs 'jsonStyle', which is a string, not the Javascript variable name. If I instead set the style key to a dictionary version of the style string I output, it will include that JSON object for every subsequent JSON element. I don’t know how to let style reference a Javascript variable name when I encode it in Python.

I would prefer not to have to do string manipulation for this, but I could fall back on that.

Edit:

I suppose that I am not actually using JSON. I output them as variables to a Javascript file so that I can include them as JSON objects in another Javascript file. Looks like I’ll either need to use YAML or just do some sort of string editing and abandon strict JSON encoding.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:11:01+00:00Added an answer on June 4, 2026 at 11:11 pm

    The format you want to write is not JSON. The format is very specific of what can be a value in a json object, and it doesn’t have the concept of a javascript variable. What you’re trying to write is javascript, not JSON – and that’s not the same.

    So you can eiter simply try to remove the quotes around your special variables, or write your own serializer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a program that generates a single large table of information. The
I am writing a program that generates excel reports, currently using the Microsoft.Interop.Excel reference.
I'm writing a program that creates and edits directories and files in a file
I'm writing a Haskell program which generates an XML file. Apparently it is considered
I am writing a multi-threaded Java program that generates lot of random numbers. Additional
I'm working on a program that generates an FDF file for filling in an
I'm writing a program that reads a series of tasks from an XML file
I am writing a program that generates standard alias names per table name. In
I was writing a little program that takes a list and generates a menu
My situation is the following: I am writing a toolbox that generates two libraries.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.